MCPcopy Index your code
hub / github.com/TheAlgorithms/JavaScript / findCombinations

Function findCombinations

Backtracking/AllCombinationsOfSizeK.js:6–21  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4 let currentValue = 1
5
6 function findCombinations() {
7 if (currentCombination.length === k) {
8 // Add the array of size k to the allCombinations array
9 allCombinations.push([...currentCombination])
10 return
11 }
12 if (currentValue > n) {
13 // Check for exceeding the range
14 return
15 }
16 currentCombination.push(currentValue++)
17 findCombinations()
18 currentCombination.pop()
19 findCombinations()
20 currentValue--
21 }
22
23 findCombinations()
24

Callers 1

generateCombinationsFunction · 0.85

Calls 2

pushMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected