diff --git a/README.md b/README.md
index f185c714d..6659888fa 100644
--- a/README.md
+++ b/README.md
@@ -64,6 +64,7 @@
* [`quickSort`](#quicksort)
* [`remove`](#remove)
* [`sample`](#sample)
+* [`sampleSize`](#samplesize)
* [`shuffle`](#shuffle)
* [`similarity`](#similarity)
* [`symmetricDifference`](#symmetricdifference)
@@ -260,15 +261,6 @@
-### _Uncategorized_
-
-
-View contents
-
-* [`sampleSize`](#samplesize)
-
-
-
---
## 🔌 Adapter
@@ -1199,6 +1191,38 @@ sample([3, 7, 9, 11]); // 9
[⬆ Back to top](#table-of-contents)
+### sampleSize
+
+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 argument, `n` to get only one element at random from the array.
+
+```js
+const sampleSize = ([...arr], n = 1) => {
+ let m = arr.length;
+ while (m) {
+ const i = Math.floor(Math.random() * m--);
+ [arr[m], arr[i]] = [arr[i], arr[m]];
+ }
+ return arr.slice(0, n);
+};
+```
+
+
+Examples
+
+```js
+sampleSize([1, 2, 3], 2); // [3,1]
+sampleSize([1, 2, 3], 4); // [2,3,1]
+```
+
+
+
+ [⬆ Back to top](#table-of-contents)
+
+
### shuffle
Randomizes the order of the values of an array, returning a new array.
@@ -4370,35 +4394,6 @@ yesNo('Foo', true); // true
[⬆ Back to top](#table-of-contents)
----
- ## _Uncategorized_
-
-### sampleSize
-
-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 argument, `n` to get only one element at random from the array.
-
-```js
-const sampleSize = ([...arr], n = 1) => {
- let m = arr.length;
- while (m) {
- const i = Math.floor(Math.random() * m--);
- [arr[m], arr[i]] = [arr[i], arr[m]];
- }
- return arr.slice(0, n);
-};
-```
-
-```js
-sampleSize([1, 2, 3], 2); // [3,1]
-sampleSize([1, 2, 3], 4); // [2,3,1]
-```
-
- [⬆ back to top](#table-of-contents)
-
## Collaborators
diff --git a/docs/index.html b/docs/index.html
index 6a66cb59d..f36e25510 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -59,7 +59,7 @@
wrapper.appendChild(box);
box.appendChild(el);
});
- }
30 seconds of code Curated collection of useful JavaScript snippets that you can understand in 30 seconds or less.
Adapter
call
Given a key and a set of arguments, call them when given a context. Primarily useful in composition.
Use a closure to call a stored key with stored arguments.
Use Math.random() to generate a random number, multiply it by length and round it of to the nearest whole number using Math.floor(). This method also works with strings.
Gets n random elements at unique keys from array up to the size of array.
Shuffle the array using the Fisher-Yates algorithm. Use Array.slice() to get the first n elements. Omit the second argument, n to get only one element at random from the array.
const sampleSize = ([...arr], n = 1) => {
+ let m = arr.length;
+ while (m) {
+ const i = Math.floor(Math.random() * m--);
+ [arr[m], arr[i]] = [arr[i], arr[m]];
+ }
+ return arr.slice(0, n);
+};
+
Gets n random elements at unique keys from array up to the size of array.
Shuffle the array using the Fisher-Yates algorithm. Use Array.slice() to get the first n elements. Omit the second argument, n to get only one element at random from the array.
const sampleSize = ([...arr], n = 1) => {
- let m = arr.length;
- while (m) {
- const i = Math.floor(Math.random() * m--);
- [arr[m], arr[i]] = [arr[i], arr[m]];
- }
- return arr.slice(0, n);
-};
-