Using i > 0 blocks legitimate nesting as well as sibling repeats.
Acceptance criteria
- 1.#out should show six subsets.
Using i > 0 blocks legitimate nesting as well as sibling repeats.
const items = [1, 2, 2].sort((a, b) => a - b); let total = 0; const path = []; function go(start) { total++; for (let i = start; i < items.length; i++) { if (i > 0 && items[i] === items[i - 1]) continue; path.push(items[i]); go(i + 1); path.pop(); } } go(0); document.querySelector('#out').textContent = total === 6 ? "six subsets" : "got " + total;
Output ready when you are
Press Run to render your code, or Submit to validate your solution.