Skip to content

Commit 447090d

Browse files
authored
Create staircase-problem.js
1 parent 0f84f6a commit 447090d

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

staircase-problem.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const numWays = (N, paths=[], steps) => {
2+
if(N >= 0){
3+
if(N === 0){
4+
allPaths.push([0].concat(paths.reverse()));
5+
return;
6+
}
7+
else{
8+
for(let i=0; i < steps.length; i++){
9+
paths = paths.concat(N);
10+
numWays(N-steps[i],paths,steps);
11+
paths = paths.slice(0, paths.length - 1);
12+
}
13+
}
14+
}
15+
}
16+
17+
const N = 4;
18+
const allPaths = [];
19+
const steps = [1,2];
20+
console.log(numWays(N,[],steps));
21+
console.log(allPaths);

0 commit comments

Comments
 (0)