Skip to content

Commit

Permalink
replace shuffle
Browse files Browse the repository at this point in the history
  • Loading branch information
vigan-abd committed Nov 2, 2023
1 parent 8928cca commit 1aa1b9b
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/shuffle.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@
const shuffle = (array) => {
const clone = [...array]
const length = clone.length
for (let i = 0; i < length; i++) {
const mov = Math.floor(Math.random() * length)
const tmp = clone[mov]
clone[mov] = clone[i]
clone[i] = tmp
for (let i = length - 1; i > 0; i--) {
const index = Math.floor(Math.random() * (i + 1)); // random index from 0 to i
[clone[i], clone[index]] = [clone[index], clone[i]] // swap elements
}

return clone
Expand Down

0 comments on commit 1aa1b9b

Please sign in to comment.