Proposal: Static sort method on Array
claude.pache at gmail.com
Sat Apr 7 21:06:38 UTC 2018
> Le 7 avr. 2018 à 21:59, Rob Ede <robjtede at icloud.com> a écrit :
> I don't like the fact the only way to sort is in-place with Array#sort and I can't be the first to feel this way or wonder why there isn't a built-in solution.
> I'm considering creating a proposal to add an Array.sort() method that takes an array and returns a new array. It seems like such a simple addition that would remove the need to import lodash, write a helper function or use a slightly less clear and possibly slower technique like `[...arr].sort()`.
`Array.from` (or indeed `[...arr]`) is a generic built-in way to create a new array, and is fine to use in every occasion where you need a copy. (Before ES6, there was already `arr.slice(0)`.) I don’t think it is appropriate to have an *additional* way to copy arrays for this specific case (it would be one more thing to learn).
More information about the es-discuss