feat: shuffleInPlace

This commit is contained in:
cha0s 2020-05-21 08:55:07 -05:00
parent 3973b74ff1
commit ada5754083

View File

@ -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
}
}