There are some existing threads about shuffling JS arrays, but they all seem not trivial and not elegant, consisting of many lines of code.
I encountered some blog that suggests the following one line "workaround":
yourArray.sort(function() { return 0.5 - Math.random() });
If you're not familiar with how sorting algorithms work, I'll explain here briefly that it's always about comparing two values of the array, and then making a decision. The proposed solution "overrides" the default comparison function with another function that for every comparison of two cells, generates a random value (on each comparison it randomly decides which is greater than which).
The problem with it, is that I can't know which sorting algorithm is used by each web browser. For some sorting algorithms, e.g. BubbleSort, such a function will probably cause the sorting algorithm to run forever, as it will have 1/2^(length) probability to have a run without any swap. It seems to also be problematic for Quicksort. I think it will finish regularly only if the web browser uses MergeSort or HeapSort
Did anyone try it and can tell whether it is safe or recommend on another solution?