Problems with sort function
KSXGitHub opened this issue · comments
sort()
usesArray.prototype.sort
https://github.com/galkowskit/denofun/blob/55d9b59ff46523a5113ba99f6ecfb3f5334abb2a/lib/sort.ts#L12
- It mutates the array
- It does not support non-Array
- It does not support function returning number other than -1, 0, 1 while
Array.prototype.sort
does, for example:
myArray.sort((a, b) => a - b)
That's clearly a non-intended behavior. :D
Good catch.
I think you should re-add "enhancement" tag:
I did say
It does not support function returning number other than -1, 0, 1 while
Array.prototype.sort
does
What I meant is you should allow callback function to return numbers other than -1, 0, and 1, so that the following one-liner works (it already works in vanilla JavaScript, but TypeScript definition does not allow it):
sort((a, b) => a - b, myArray)
Does sort function still mutates array?
It shouldn't, no.