> Le 7 avr. 2018 à 21:59, Rob Ede <robjt...@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.
> Obviously, searching "javascript array.sort" doesn't produce any helpful 
> results to see if someone has suggested this before since all the results 
> relate to Array#sort.
> 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). 

es-discuss mailing list

Reply via email to