Skip to content

Commit 686690d

Browse files
📚 docs(shuffle/_shuffle): Document function signatures.
1 parent 49b7b19 commit 686690d

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/api/shuffle.js

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
import _shuffle from '../kernel/_shuffle.js';
22
import sample from './sample.js';
33

4+
/**
5+
* Shuffle array in-place between positions i and j-1 (inclusive).
6+
* The other positions are left untouched.
7+
* @function
8+
* @param {Array} a The input array.
9+
* @param {number} i The inclusive left bound.
10+
* @param {number} j The non-inclusive right bound.
11+
*/
412
const shuffle = _shuffle(sample);
513
export default shuffle;

src/kernel/_shuffle.js

+16-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
/**
2-
* Shuffle array by sampling the complete array.
2+
* Shuffle the array by sampling the entire array.
3+
*
4+
* @param {Function} sample The sample function.
5+
* @return {Function} The shuffle function.
36
*/
7+
const _shuffle = (sample) => {
8+
/**
9+
* Shuffle array in-place between positions i and j-1 (inclusive).
10+
* The other positions are left untouched.
11+
*
12+
* @param {Array} a The input array.
13+
* @param {number} i The inclusive left bound.
14+
* @param {number} j The non-inclusive right bound.
15+
*/
16+
const shuffle = (a, i, j) => sample(j - i, a, i, j);
17+
return shuffle;
18+
};
419

5-
const _shuffle = (sample) => (a, i, j) => sample(j - i, a, i, j);
620
export default _shuffle;

0 commit comments

Comments
 (0)