Skip to content

Commit 0dd55b3

Browse files
📚 docs(_fisheryates): Add important note about the definition of k.
1 parent 67bdac4 commit 0dd55b3

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/kernel/_fisheryates.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
const _fisheryates = (randint) => (n, a, i, j) => {
66
// We will swap at most n elements
7-
7+
// NOTE: When n = j - i, the last swap swaps a[j-1] with itself,
8+
// which is a NOOP. /!\ HOWEVER, the last swap is NOT a NOOP when
9+
// n < j - i. Hence we cannot let k = i + n - 1 in general.
810
const k = i + n;
911

1012
for (; i < k; ++i) {

0 commit comments

Comments
 (0)