Update sampleSize.md
This commit is contained in:
@ -2,8 +2,12 @@
|
||||
|
||||
Gets `n` random elements at unique keys from `array` up to the size of `array`.
|
||||
|
||||
Shuffle the array using the [Fisher-Yates algorithm](https://github.com/chalarangelo/30-seconds-of-code#shuffle).
|
||||
Use `Array.slice()` to get the first `n` elements.
|
||||
Omit the second arguent, `n` to get only one element at random from the array.
|
||||
|
||||
```js
|
||||
const sampleSize = (arr,n=1) => {
|
||||
const sampleSize = ([...arr],n=1) => {
|
||||
let m = arr.length;
|
||||
while (m) {
|
||||
const i = Math.floor(Math.random() * m--);
|
||||
|
||||
Reference in New Issue
Block a user