Skip to content

Commit d6b751c

Browse files
committed
feat: make solution code more dry
1 parent 507c436 commit d6b751c

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

15_totalIntegers/solution/totalIntegers-solution.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
const totalIntegers = function(obj, count = 0) {
1+
const totalIntegers = function (obj, count = 0) {
2+
const isObject = (value) => typeof value === 'object' && value !== null;
23

34
if (typeof obj !== 'object' || obj === null) {
45
return;
@@ -9,7 +10,7 @@ const totalIntegers = function(obj, count = 0) {
910
for (const el of elements) {
1011
if (Number.isInteger(el)) {
1112
count++;
12-
} else if (typeof el === 'object' && el !== null) {
13+
} else if (isObject(el)) {
1314
count += totalIntegers(el);
1415
}
1516
}

0 commit comments

Comments
 (0)