From 227f6a195894d3eb0657cf1ac409a1c912a4f7a0 Mon Sep 17 00:00:00 2001 From: Jesse Schwartzentruber Date: Thu, 20 Apr 2017 15:15:13 -0400 Subject: [PATCH] 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. --- random/random.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/random/random.js b/random/random.js index e008648..3d8cd8b 100644 --- a/random/random.js +++ b/random/random.js @@ -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; }