Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

So far as I can tell,

isSorted([0, 0, 0], [4, 20, 0, 0, 0]) is true

(the code doesn't care about values in sorted which never occur in original and doesn't check these arrays are the same length)

But

isSorted([10, 5, 0], [0, 5, 10]) is false

(for some reason the code checks that original is sorted, rather than sorted...)

That's OK though, the original exercise exists because most programmers can't get even basic algorithms right, so you're helping to demonstrate that.



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...


It 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".


Additionally your issorted is n^2 which may not finish if you're testing an nlogn sorting algorithm.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: