feat: shuffleInPlace
This commit is contained in:
parent
3973b74ff1
commit
ada5754083
|
@ -13,3 +13,13 @@ export function fromObject(object) {
|
|||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
export function shuffleInPlace(array) {
|
||||
let i = 0, j = 0, temp = null;
|
||||
for (i = array.length - 1; i > 0; i -= 1) {
|
||||
j = Math.floor(Math.random() * (i + 1))
|
||||
temp = array[i]
|
||||
array[i] = array[j]
|
||||
array[j] = temp
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user