write an algorithm to determine if a number is "happy".
A happy number is a number defined by the following process:
Starting with any positive integer, replace the number by the sum of the squares of its digits,
and repeat the process until the number equals 1 (where it will stay),
or it loops endlessly in a cycle which does not include 1.
Those numbers for which this process ends in 1 are happy numbers.
var isHappy = function(n) {
let store = new Set();
// 當等於 1 (Happy Number) 或是重覆數字出現 (無窮迴圈) 就停
while(n!==1 && !store.has(n)){
store.add(n)
n = cal(n);
// n = n.toString().split('').reduce((acc, cur) => acc + Math.pow(cur, 2), 0);
}
function cal(x){
var result = 0;
while(x>0){
result += (x%10)*(x%10);
x = Math.floor(x/10)
}
return result;
}
return n ==1;
};