Performance improvement of random.pop()

This does not do the same array type checks as random.item(), but these
should be standardized throughout the module.
This commit is contained in:
Jesse Schwartzentruber 2017-04-20 15:15:13 -04:00
parent 8e084eb878
commit 227f6a1958
1 changed files with 3 additions and 2 deletions

View File

@ -146,8 +146,9 @@ var random = {
// Removes and returns a random item from an array
let i, obj;
obj = this.item(arr);
arr.splice(arr.indexOf(obj), 1);
i = this.number(arr.length);
obj = arr[i];
arr.splice(i, 1);
return obj;
}