Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d789f62

Browse files
Merge pull request fnplus#364 from hp250497/master
added logic for Magic number
2 parents 6ed15c5 + b04b689 commit d789f62

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
const readline = require("readline");
3+
4+
const rl = readline.createInterface({
5+
input: process.stdin,
6+
output: process.stdout
7+
});
8+
9+
rl.question("Enter the number: ", a => {
10+
var n=parseInt(a)
11+
var length= a.length;
12+
while(length>1){
13+
var arr = n.toString(10).replace(/\D/g, '0').split('').map(Number);
14+
15+
16+
n = arr.reduce(myFunc);
17+
length=n.toString().length;
18+
}
19+
if(n==1)
20+
console.log("The number is a magic number");
21+
else
22+
console.log("The number is not a magic number");
23+
process.exit();
24+
});
25+
26+
27+
function myFunc(total, num) {
28+
return total + num;
29+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /