Answer the question
In order to leave comments, you need to log in
Why does the If condition in the recursion return undefined?
Checked the ELSE thread. Everything works correctly there. When the isHappy(1) function is called, undefined is returned instead of true.
var isHappy = function(n) {
if (n === 1) return true
else if (n != 1 && n < 10) return false
else {
const array = Array.from(`${n}`);
const output = array.map(num =>num * num).reduce((acc, curr) => acc + curr);
isHappy(output);
}
};
console.log(isHappy(19))
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question