What is your hint or solution suggestion?
Split into integer array. Square using Array.map and add all integers. if(sum == 89|sum == 1)
, return answer, otherwise, return iteratedSquare(sum)
, which creates a recursive function.
Solution 1
function iteratedSquare(n) {
var result = Array.from(n.toString()).map(Number).map(x => x ** 2);
var sum = result.reduce((a, b)=> a + b, 0);
if(sum == 89|sum == 1){
return sum;
}
else{
return iteratedSquare(sum)
}
}
Challenge: Iterated digits squaring
Link to the challenge: