Happy Numbers

Can't understand why my code doesn't work, 19 is coming back false but does go through recursion to get to [1,0,0] and if I start with 100 it returns true?

 * @param {number} n
 * @return {boolean}
 */
var isHappy = function(n, counter = 0) {
  let result = false
 if (counter < 10){
  
  let arrOfDigits = Array.from(String(n), Number)
    console.log(arrOfDigits)
    let happyStep = arrOfDigits.reduce((a,b) => a*a + b*b)

    if(happyStep === 1){
      return result = true
    } else {
      counter++
      isHappy(happyStep, counter)
    }
 }
 return result
};

console.log(isHappy(19)) ```
Comments (0)