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:
parent
8e084eb878
commit
227f6a1958
1 changed files with 3 additions and 2 deletions
|
@ -146,8 +146,9 @@ var random = {
|
||||||
// Removes and returns a random item from an array
|
// Removes and returns a random item from an array
|
||||||
let i, obj;
|
let i, obj;
|
||||||
|
|
||||||
obj = this.item(arr);
|
i = this.number(arr.length);
|
||||||
arr.splice(arr.indexOf(obj), 1);
|
obj = arr[i];
|
||||||
|
arr.splice(i, 1);
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue