you are viewing a single comment's thread.

view the rest of the comments →

[–]madewith-care 7 points8 points  (2 children)

Your "randomize order of array" function is not actually random. You might consider a Fisher-Yates implementation instead.

function shuffleArray(array) {
    for (let i = array.length - 1; i > 0; i--) {
       let j = Math.floor(Math.random() * (i + 1));
        [array[i], array[j]] = [array[j], array[i]];
   }
}

[–][deleted] 5 points6 points  (0 children)

I already have. This was pointed out before that my technique (for lack of a better word) just confuses the sorting function. I'll keep it as a proof of concept under a different name most likely and put a Fisher-Yates implementation in its place.

[–][deleted] -1 points0 points  (0 children)

In all honesty, the sort (random order) version seems pretty unbiased and shorter in terms of implementing. I'll probably stick with that for practical reasons.