That somewhat works, because Math.random() - 0.5 is a random number that may be positive or negative, so the sorting function reorders elements randomly.
But because the sorting function is not meant to be used this way, not all permutations have the same probability.
WARNING why you shouldn't use this method in cryptographic functions: javascript.info/task/shuffle
Thanks for contribute. 🙂
It also breaks down when there are key collisions.
Sorting by non-unique keys is not shuffling.
Fisher-Yeats is trivial to implement and theoretically correct -- use that instead.