diff --git a/Sorts/BogoSort.js b/Sorts/BogoSort.js index eeb4f7feeb..8643e61d08 100644 --- a/Sorts/BogoSort.js +++ b/Sorts/BogoSort.js @@ -15,11 +15,9 @@ export function isSorted(array) { * Shuffles the given array randomly in place. */ function shuffle(array) { - for (let i = array.length - 1; i; i--) { - const m = Math.floor(Math.random() * i) - const n = array[i - 1] - array[i - 1] = array[m] - array[m] = n + for (let i = array.length - 1; i > 0; i--) { + const j = Math.floor(Math.random() * (i + 1)) + ;[array[i], array[j]] = [array[j], array[i]] } }