5 Commits
Author SHA1 Message Date
dualfroz 71238c0192 Describe this repository 2026-10-22 21:07:01 +02:00
dualfroz 5894b8b560 fix(permutations-heap): do the swaps on a copy of the input
Heap's Algorithm generates each permutation by swapping two elements of a
working array in place, and that working array was the argument itself, so
permutationsHeap([1, 2, 3]) left the caller holding [3, 2, 1]. Two calls on
one array returned different lists, and a frozen array threw.

Copy the input up front and swap on the copy, as shuffle and numericSort
already do. The returned permutations are unchanged.
2026-09-03 14:06:28 +02:00
upstream cd7bef4165 Upstream simple-statistics/simple-statistics state of the touched files before afe3d20779 2026-09-03 14:06:28 +02:00
dualfroz 24fe35e78e fix(combinations-replacement): return an empty list for a non-positive group size
combinationsReplacement recurses on x.slice(i, x.length), which at i = 0 is
as long as the input, so the only exit left is the k === 1 base case. For
k <= 0 the counter starts below that case and moves away from it, and the
recursion overflows the stack. The sibling combinations recurses on
x.slice(i + 1, x.length), runs out of input and returns [] for the same
arguments.

Guard the non-positive group size up front so both functions agree.
2026-09-03 14:04:54 +02:00
upstream 1aa682fd34 Upstream simple-statistics/simple-statistics state of the touched files before e26d2c41ca 2026-09-03 14:04:54 +02:00