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 consulting? Or a new website? Send me an email and we can get started. www.isiahmeadows.com On Sat, Apr 7, 2018 at 6:18 PM, T.J. Crowder <tj.crow...@farsightsoftware.com> wrote: > On Sat, Apr 7, 2018 at 8:59 PM, Rob Ede <robjt...@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 > > _______________________________________________ > es-discuss mailing list > es-discuss@mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > _______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss