-
Notifications
You must be signed in to change notification settings - Fork 18
Alternative approachesΒ #84
Description
Description
I'm sorry if understood the proposal wrong or didn't research it well enough but why it's better to have toReversed(), toSorted() along with reverse(), sort()? (I can agree with toSpliced() and with(...))
I can't really see the problem to just use spread syntax or "standard" method, I'll demonstrate it on your examples.
reverse()
Proposal approach
const sequence = [1, 2, 3];
sequence.toReversed(); // => [3, 2, 1]
sequence; // => [1, 2, 3]Spread syntax approach
const sequence = [1, 2, 3];
[...sequence].reverse(); // => [3, 2, 1]
sequence; // => [1, 2, 3]sort()
Proposal approach
const outOfOrder = new Uint8Array([3, 1, 2]);
outOfOrder.toSorted(); // => Uint8Array [1, 2, 3]
outOfOrder; // => Uint8Array [3, 1, 2]"Standard" approach
const outOfOrder = new Uint8Array([3, 1, 2]);
new Uint8Array(outOfOrder).sort(); // => Uint8Array [1, 2, 3]
outOfOrder; // => Uint8Array [3, 1, 2]Conclusion
As you can see it's not a big problem to solve this with already existed methods it's niether making code a lot longer nor more complicated.
If you can give more examples on what your proposal solves with real-world examples, otherwise it's just polution of the Array and TypeArray, a newbie would barely see the diffrence and why there splice() and toSpliced() at the same time.
Again, maybe I don't get it and not taking something to an account. However your examples showing only with(...) usage as "reasonable" (as for me).