Sort algorithms in JS