Skip to content

Commit 73a0f10

Browse files
committed
feat/ add solution
1 parent 49da653 commit 73a0f10

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed
Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
1-
const totalIntegers = function() {
2-
// Replace this comment with the solution code
1+
const isInteger = (number) => {
2+
switch (true) {
3+
case (Number.isNaN(number)):
4+
case (typeof number !== 'number'):
5+
case (number % 1 !== 0):
6+
return false;
7+
default:
8+
return true;
9+
}
310
};
4-
11+
12+
const totalIntegers = function(array, count = 0) {
13+
if (!Array.isArray(array)) return;
14+
for (const el of array) {
15+
if (isInteger(el)) ++count;
16+
if (Array.isArray(el)) count += totalIntegers(el);
17+
}
18+
return count;
19+
};
20+
521
// Do not edit below this line
622
module.exports = totalIntegers;

0 commit comments

Comments
 (0)