X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=node_modules%2Fgrunt-legacy-util%2Fnode_modules%2Flodash%2Fsample.js;fp=node_modules%2Fgrunt-legacy-util%2Fnode_modules%2Flodash%2Fsample.js;h=1a4d813695f6dfa61243bd4ff2b8b83ef35a7f9d;hp=0000000000000000000000000000000000000000;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad diff --git a/node_modules/grunt-legacy-util/node_modules/lodash/sample.js b/node_modules/grunt-legacy-util/node_modules/lodash/sample.js new file mode 100644 index 000000000..1a4d81369 --- /dev/null +++ b/node_modules/grunt-legacy-util/node_modules/lodash/sample.js @@ -0,0 +1,25 @@ +var baseRandom = require('./_baseRandom'), + isArrayLike = require('./isArrayLike'), + values = require('./values'); + +/** + * Gets a random element from `collection`. + * + * @static + * @memberOf _ + * @category Collection + * @param {Array|Object} collection The collection to sample. + * @returns {*} Returns the random element. + * @example + * + * _.sample([1, 2, 3, 4]); + * // => 2 + */ +function sample(collection) { + var array = isArrayLike(collection) ? collection : values(collection), + length = array.length; + + return length > 0 ? array[baseRandom(0, length - 1)] : undefined; +} + +module.exports = sample;