We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5c39e87 commit 2b8b0d3Copy full SHA for 2b8b0d3
1 file changed
Sorts/BogoSort.js
@@ -15,11 +15,9 @@ export function isSorted(array) {
15
* Shuffles the given array randomly in place.
16
*/
17
function shuffle(array) {
18
- for (let i = array.length - 1; i; i--) {
19
- const m = Math.floor(Math.random() * i)
20
- const n = array[i - 1]
21
- array[i - 1] = array[m]
22
- 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]]
23
}
24
25
0 commit comments