4 ms·
I fixed two silly mistakes thanks to your comment! Added at the beginning of isSorted(): if (original.length != sorted.length) return false; Chan
by nayuki 4y ago
I fixed two silly mistakes thanks to your comment!
Added at the beginning of isSorted():
if (original.length != sorted.length)
return false;
Changed the wrong ordering check:
if (i > 0 && original[i] < original[i - 1])
> most programmers can't get even basic algorithms right, so you're helping to demonstrate that
Now this puts my entire body of published work into question...
- Schroedingersat 4y agoAdditionally your issorted is n^2 which may not finish if you're testing an nlogn sorting algorithm.
- tialaramex 4y agoIt occurs to me that the "you're helping" might read as snark and it wasn't really intended that way, or at least, not as snark at you, but rather all of us. It's silly to reject help from e.g. peer review, static analysis, smarter / safer languages. If you look at some tool and say "What kind of idiot would make the mistakes this catches?" the answer is almost certainly "idiots like you".