You need to write a function that takes a number, and adds the square of each digit until it becomes 1, unless of course it is possible with this number. For example:
x = 23 -> 2 ^ 2 + 3 ^ 2 = 13 -> 1 ^ 2 + 3 ^ 2 = 10 -> 1 ^ 2 + 0 ^ 2 = 1 -> true
x = 22 -> 2 ^ 2 + 2 ^ 2 = 8 -> false
Numbers can be different, for example, 0, 1, 12, 123, 1234 ... If such a number is given that at the end becomes 1, then let it return true, and if not, false. There are such numbers that will endlessly repeat the action, then, when in one part the same numbers will be repeated. In the current case too, empty returns false. (Do not use prototype.) In my examples, the codes only do it once. Probably you need to do a while loop (For example: while (x! = 1) {...}), but I don’t know how.
code 1
function solution(x) { let s=0; x = x.toString().split(''); for (let i=0; i<x.length; i++) { s += Math.pow(x[i],2); } if (s==1) { return true } return false } console.log(solution(23)); code 2
function solution(x) { let y; y=(x + '').split('') .map(b => parseInt(b)) .reduce((a,b) => a += b * b, 0); if (y==1) { return true } return false } console.log(solution(23));