'Armstrong number using prompt sync
var num = require("prompt-sync")()("message")
const armstrongNumber = (num) => {
const toArray = num.toString().split('').map(Number);
const newNum = toArray.map(a => {return a**3}).reduce((a, b) => a + b); //Here we need to change the expontenial power accordingly to sum of own digits
if(newNum == num){
console.log('This is an armstrong number');
}else{
console.log('This is not an armstrong number');
}
}
armstrongNumber(num)
how to do if I use loop statements in the function? I used while loop in the function, but then in the console most of the armstrong values returning it as 'This is not an armstrong number'
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
