Proposal: Static sort method on Array

T.J. Crowder tj.crowder at farsightsoftware.com
Sat Apr 7 22:18:26 UTC 2018


On Sat, Apr 7, 2018 at 8:59 PM, Rob Ede <robjtede at icloud.com> 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 = Array.from(originalArray).sort();
// or
let newArray = [...originalArray].sort();
```

I don't know that we need a new static for it. Unless the motivation is to
allow insertion sort or other sort algorithms that work best when creating
a new array as a result? But if we assume `Array.prototype.sort` already
uses quicksort or mergesort or similar, I'm not seeing much reason to add a
new static to allow insertsion sort or similar...

Can you expand on use cases and why the above aren't sufficient?

-- T.J. Crowder
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180407/1a7a61fb/attachment-0001.html>


More information about the es-discuss mailing list