Gets `n` random elements at unique keys from `array` up to the size of `array`.
sampleSize([1, 2, 3], 2)
// => [3, 1]
sampleSize([1, 2, 3], 4)
// => [2, 3, 1]
Name | Type | Attribute | Description |
---|---|---|---|
array | The array to sample. | ||
n | The number of elements to sample. |
{ "comment": "/**\r\n * Gets `n` random elements at unique keys from `array` up to the\r\n * size of `array`.\r\n *\r\n * @since 4.0.0\r\n * @category Array\r\n * @param {Array} array The array to sample.\r\n * @param {number} [n=1] The number of elements to sample.\r\n * @returns {Array} Returns the random elements.\r\n * @example\r\n *\r\n * sampleSize([1, 2, 3], 2)\r\n * // => [3, 1]\r\n *\r\n * sampleSize([1, 2, 3], 4)\r\n * // => [2, 3, 1]\r\n */", "meta": { "range": [ 463, 924 ], "filename": "sampleSize.js", "lineno": 20, "path": "C:\\Users\\beaujeup\\projects\\jsdoc-template\\examples\\lodash\\lodash-repo", "code": { "id": "astnode100007959", "name": "sampleSize", "type": "FunctionDeclaration", "paramnames": [ "array", "n" ] }, "vars": { "length": "sampleSize~length", "n": "sampleSize~n", "index": "sampleSize~index", "lastIndex": "sampleSize~lastIndex", "result": "sampleSize~result", "rand": "sampleSize~rand", "value": "sampleSize~value", "result[undefined]": "sampleSize~result[undefined]" } }, "description": "Gets `n` random elements at unique keys from `array` up to the\rsize of `array`.", "since": "4.0.0", "tags": [ { "originalTitle": "category", "title": "category", "text": "Array", "value": "Array" } ], "params": [ { "type": { "names": [ "Array" ] }, "description": "The array to sample.", "name": "array" }, { "type": { "names": [ "number" ] }, "optional": true, "defaultvalue": 1, "description": "The number of elements to sample.", "name": "n" } ], "returns": [ { "type": { "names": [ "Array" ] }, "description": "Returns the random elements." } ], "examples": [ "sampleSize([1, 2, 3], 2)\r// => [3, 1]\r\rsampleSize([1, 2, 3], 4)\r// => [2, 3, 1]" ], "name": "sampleSize", "longname": "sampleSize", "kind": "function", "scope": "global", "___id": "T000002R000731", "___s": true, "filepath": "sampleSize.js" }