1.0.2 • Published 9 years ago
random-array-subset v1.0.2
random-array-subset
Returns an array of a specified length containing a random subset of elements from a given array.
Example of normal use.
var originalArray = ["a","b","c","d","e","f","g","h","i","j"];
//request a random array of 4 elements.
var newArray = require("./random-array-subset")(originalArray,4);
console.log(newArray); // ["j","g","d","c"]
Example of requesting more elements than are in the original array.
//array with length == 10
var originalArray = ["a","b","c","d","e","f","g","h","i","j"];
//request a random array of 15 elements. Will retun only 10.
var newArray = require("./random-array-subset")(originalArray,15);
console.log(newArray); // [ 'c', 'i', 'f', 'b', 'h', 'j', 'a', 'g', 'e', 'd' ]
Example of requesting 0 items
var originalArray = ["a","b","c","d","e","f","g","h","i","j"];
//request a random array of 0 elements.
var newArray = require("./random-array-subset")(originalArray,0);
//returns empty array
console.log(newArray); // [ ]
License
MIT, see LICENSE.md for details.