if you want to adhere to the python/jslint philosophy of “there should be one
and preferably only one common design-pattern to do it”, then array.from is the
most suitable candidate for copying/coercing lists. it can generalise to
common pseudo-lists like function-arguments and
`slice()` is better than `Array.from()` if you already have an array
because you can chain it with the other Array.prototype methods.
Good point about not needing it after you've done a map/filter/concat or
whatever, since you already have a new array.
However I agree with the thrust of a
When I need a non-in-place sort, I just do `array.slice().sort()`.
It's pretty easy, and it still chains. (In my experience, it's rarely
necessary considering most chaining methods like `.map` and `.filter`
already return new instances.)
-
Isiah Meadows
m...@isiahmeadows.com
Looking for web
On Sat, Apr 7, 2018 at 8:59 PM, Rob Ede wrote:
> ...I'm considering creating a proposal to add an Array.sort()
> method that takes an array and returns a new array...
That would be:
```js
let newArray = originalArray.slice().sort();
// or
let newArray =
To be super explicit: given an array 'a', then: `Array.from(a).sort()` will
return you a sorted clone. That works even if `a` has an iterator or is an
array-like object. That's just seven characters longer than
`Array.sort(a)`, which is what you seem to be proposing.
To be sure, I don't think
> Le 7 avr. 2018 à 21:59, Rob Ede 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
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
7 matches
Mail list logo