Skip to content

Commit 2f18043

Browse files
authored
added prettier config
1 parent aa5079d commit 2f18043

File tree

2 files changed

+20
-24
lines changed

2 files changed

+20
-24
lines changed

array-sum.js

-24
This file was deleted.

nested-array-sum.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const findArraySum = (array, index, sum) => {
2+
if (index === array.length) {
3+
return sum;
4+
}
5+
6+
let element = array[index];
7+
8+
if (Array.isArray(element)) {
9+
element = findArraySum(element, 0, 0);
10+
}
11+
12+
sum += element;
13+
14+
return findArraySum(array, index + 1, sum);
15+
};
16+
17+
/*
18+
example input
19+
const array = [1,[11,42,[8, 1], 4, [22,21]]];
20+
*/

0 commit comments

Comments
 (0)