forked from TheAlgorithms/JavaScript
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArmstrongNumber.js
More file actions
Latest commit
24 lines (19 loc) · 600 Bytes
/
Copy pathArmstrongNumber.js
File metadata and controls
24 lines (19 loc) · 600 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
/**
* Author: dephraiim
* License: GPL-3.0 or later
*
* An Armstrong number is equal to the sum of its own digits each raised to the power of the number of digits.
* For example, 370 is an Armstrong number because 3*3*3 + 7*7*7 + 0*0*0 = 370.
* An Armstrong number is often called Narcissistic number.
*
*/
constarmstrongNumber=(num)=>{
if(num<0||typeofnum!=='number')returnfalse
letnewSum=0
constnumArr=num.toString().split('')
numArr.forEach((num)=>{
newSum+=parseInt(num)**numArr.length
})
returnnewSum===num
}
export{armstrongNumber}