Happy Num

Run Settings
LanguageJavaScript
Language Version
Run Command
/** * @param {number} n * @return {boolean} */ let mySet=new Set(); var isHappy = function(n) { let sum=0 if(n===1){ return true; } while(sum!==1){ let array=n.toString().split("").map(x=>parseInt(x)); for(let i=0; i<array.length; i++){ sum+=array[i]*array[i]; } if(mySet.has(sum)){ return false; } else{ mySet.add(sum); } //console.log(n,sum); if(sum===1){ return true; } else{ return isHappy(sum); } } return false }; console.log(isHappy(19));
Editor Settings
Theme
Key bindings
Full width
Lines