Having trouble with a JavaScript interpreter that has a buggy Array.prototype.sort
. I want to replace it, at least for testing purposes.
I have a function called mySort(array, comparator)
, but how can I make it work like array.sort(comparator)
?
I also need to have a default comparator. Would simply using
return a<b ? -1 : a>b ? +1 : 0
be enough?
Are there any other potential issues I should be aware of?
On another note: My basic sorting function is functioning, but I'd prefer to replace it with more robust, tested code.