main
|
Last change
on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 9 months ago |
|
F4 Finalna Verzija
|
-
Property mode
set to
100644
|
|
File size:
551 bytes
|
| Line | |
|---|
| 1 | var arraySample = require('./_arraySample'),
|
|---|
| 2 | baseSample = require('./_baseSample'),
|
|---|
| 3 | isArray = require('./isArray');
|
|---|
| 4 |
|
|---|
| 5 | /**
|
|---|
| 6 | * Gets a random element from `collection`.
|
|---|
| 7 | *
|
|---|
| 8 | * @static
|
|---|
| 9 | * @memberOf _
|
|---|
| 10 | * @since 2.0.0
|
|---|
| 11 | * @category Collection
|
|---|
| 12 | * @param {Array|Object} collection The collection to sample.
|
|---|
| 13 | * @returns {*} Returns the random element.
|
|---|
| 14 | * @example
|
|---|
| 15 | *
|
|---|
| 16 | * _.sample([1, 2, 3, 4]);
|
|---|
| 17 | * // => 2
|
|---|
| 18 | */
|
|---|
| 19 | function sample(collection) {
|
|---|
| 20 | var func = isArray(collection) ? arraySample : baseSample;
|
|---|
| 21 | return func(collection);
|
|---|
| 22 | }
|
|---|
| 23 |
|
|---|
| 24 | module.exports = sample;
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.