Bump to v4.0.0.

This commit is contained in:
John-David Dalton
2015-08-24 10:34:23 -07:00
parent 4ef16c96e5
commit 0646bacd86
665 changed files with 24828 additions and 19696 deletions

25
sample.js Normal file
View File

@@ -0,0 +1,25 @@
var baseRandom = require('./internal/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;