Skip to content

Commit eef9480

Browse files
committed
Add helper method recusion pattern
1 parent e6622d8 commit eef9480

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

7-recursion/factorial.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ const factorial = (num) => {
1212
console.log(factorial(10));
1313

1414
// Recursive solution
15-
1615
const factorialRe = (num) => {
1716
if (num === 1) {
1817
return 1;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Helper Method Recursion Pattern
2+
3+
const collectOddValues = (arr) => {
4+
let result = [];
5+
6+
function helper(helperInputer) {
7+
if (helperInputer.length === 0) {
8+
return;
9+
}
10+
11+
if (helperInputer[0] % 2 !== 0) {
12+
result.push(helperInputer[0]);
13+
}
14+
15+
helper(helperInputer.slice(1));
16+
}
17+
18+
helper(arr);
19+
20+
return result;
21+
};
22+
23+
console.log(collectOddValues([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]));

0 commit comments

Comments
 (0)