-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharmstrong.js
More file actions
33 lines (31 loc) · 712 Bytes
/
armstrong.js
File metadata and controls
33 lines (31 loc) · 712 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
function arm(num){
let k= String(num).length;
let sum=0;
let n=num;
while(n!==0){
let last=n%10;//get the last digit
sum=sum+Math.pow(last,k)//this does something like this (0+3^3),(27+5^3),()
n=Math.floor(n/10);
return `${n}:${sum}`
}
if(sum===num){
return true
}
else{
return false
}
/** return sum === num ? true : false; */
}
const num=153;
console.log(arm(num))
if(arm(num)){
console.log('true');
}
else{
console.log('false');
}
/**if (isArmstrong(number)) {
console.log(number + " is an Armstrong number.");
} else {
console.log(number + " is not an Armstrong number.");
} */