diff --git a/random/random.js b/random/random.js index d7d93e4..ed40226 100644 --- a/random/random.js +++ b/random/random.js @@ -141,5 +141,14 @@ var random = { result.push(this.pick(list)); } return result; + }, + pop: function (arr) { + // Removes and returns a random item from an array + var i, obj; + + obj = Random.item(arr); + arr.splice(arr.indexOf(obj), 1); + + return obj; } }; diff --git a/tests/random/random.js b/tests/random/random.js index d8d9a9c..85b6d2a 100644 --- a/tests/random/random.js +++ b/tests/random/random.js @@ -117,4 +117,5 @@ shuffle(arr) shuffled(arr) subset(list, limit) choose(list, flat=true) +pop(arr) */