Answer the question
In order to leave comments, you need to log in
How can you find the sum of an object in another way?
https://jsfiddle.net/cahkbfx0/
Answer the question
In order to leave comments, you need to log in
function recursion(obj) {
let sum = 0;
for (let key in obj) {
if (typeof obj[key] === 'object') {
sum += recursion(obj[key]);
} else {
sum += obj[key];
}
}
return sum;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question