We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 49da653 commit 73a0f10Copy full SHA for 73a0f10
15_totalIntegers/solution/totalIntegers-solution.js
@@ -1,6 +1,22 @@
1
-const totalIntegers = function() {
2
- // Replace this comment with the solution code
+const isInteger = (number) => {
+ 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
+ }
10
};
-
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
21
// Do not edit below this line
22
module.exports = totalIntegers;
0 commit comments