We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 7a5fb8b + c50cda6 commit 07b6ca4Copy full SHA for 07b6ca4
Maths/HappyNumber.js
@@ -0,0 +1,16 @@
1
+const recursiveSum = (x, result = 0) => {
2
+ if(x){
3
+ return recursiveSum(Math.floor(n/10), res+Math.pow((n%10),2));
4
+ };
5
+ return result;
6
+};
7
+const isHappyNumber = (n, resMap = {}) => {
8
+ if(n !== 1){
9
+ if(resMap[n]){
10
+ return false;
11
+ }
12
+ resMap[n] = 1;
13
+ return isHappyNumber(recursiveSum(n), resMap);
14
15
+ return true;
16
+}
0 commit comments