fix(shuffle): fix shuffle methode for array with length <= 1

This commit is contained in:
maniolias
2020-10-01 12:43:46 +02:00
parent 40736d9da3
commit 401f6c3190
2 changed files with 80 additions and 2 deletions

View File

@@ -5,12 +5,15 @@ function rndNext(min, max) {
}
function shuffle (arr, from, to) {
if (!to) {
to = arr.length - 1;
if (arr.length <= 1){
return arr;
}
if (!from) {
from = 0;
}
if (!to) {
to = arr.length - 1;
}
const newArr = [...arr];
if (from >= to) return;
for (var current = from; current <= to; ++current) {