From 1456993dfdfa0a77912926844c55cbbe42a50dbd Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Sun, 31 Dec 2017 14:09:45 +0200 Subject: [PATCH 1/2] Update sampleSize.md --- snippets/sampleSize.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/snippets/sampleSize.md b/snippets/sampleSize.md index 6b6721b52..95e26a643 100644 --- a/snippets/sampleSize.md +++ b/snippets/sampleSize.md @@ -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--); From b6ebf3b97e6ae28edecc1edbde8104024a3644fd Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Sun, 31 Dec 2017 14:10:46 +0200 Subject: [PATCH 2/2] Update sampleSize.md --- snippets/sampleSize.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/sampleSize.md b/snippets/sampleSize.md index 95e26a643..f6187bdea 100644 --- a/snippets/sampleSize.md +++ b/snippets/sampleSize.md @@ -4,7 +4,7 @@ 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. +Omit the second argument, `n` to get only one element at random from the array. ```js const sampleSize = ([...arr],n=1) => {