effect
effect copied to clipboard
Make Array.sort Order arg optional to match js implementation.
What is the problem this feature would solve?
Array.prototype.sort's compare function is optional and it automatically handles sorting number[], string[], etc. I think we should do the same with Array.sort(et al) making the Order arg optional and relying on the default whenever possible. Array.sort() is more convenient and would be more performant than Array.sort(Order.number) or Array.sort(Order.string)
What is the feature you are proposing to solve the problem?
^
What alternatives have you considered?
No response
Array.sort is mutable so it can't be used directly, we'd have to clone the array leading to the same perf tradeoff
The mutability of .sort isn't relevant here though. I'm only suggesting that we change Array.sort(o: Order) to Array.sort(o?: Order) without changing the implementation. A compare fn isn't required when using either Array.prototype.sort or Array.prototype.toSorted unless you want to override the default behavior.
["b","a","c"].sort(Order.string) // ["a", "b", "c"]
["b","a","c"].sort() // ["a", "b", "c"]
would be more performant than
Array.sort(Order.number)orArray.sort(Order.string)
was answering to:
would be more performant than Array.sort(Order.number) or Array.sort(Order.string)