Files
30-seconds-of-code/snippets/isArmstrongNumber.md
Selim Ajimi 4b0bc342c1 Fix typos in spaces
Fix typo to fit the context

Fix typo add space

Fix small typo

Fix small typo

Fix typo

Fix typo

Fix typo

Fix typo

Fix typo

Fix typo

Fix typo

Update tail.md

Fix typo

Fix small typo

Fix typo

Fix typo

Fix typo

Fix typo

Fix small typo

Fix typo

Fix small typo

Fix typo

Fix typo

Fix typo

Fix typo

Fix typo

Fix typo

Fix typo

Fix typo

Fix typo
2017-12-22 23:48:42 +01:00

575 B

isArmstrongNumber

Checks if the given number is an Armstrong number or not.

Convert the given number into an array of digits. Use Math.pow() to get the appropriate power for each digit and sum them up. If the sum is equal to the number itself, return true otherwise false.

const isArmstrongNumber = digits => 
  ( arr => arr.reduce( ( a, d ) => a + Math.pow( parseInt( d ), arr.length ), 0 ) == digits ? true : false )( ( digits+'' ).split( '' ) );
// isArmstrongNumber(1634) -> true
// isArmstrongNumber(371) -> true
// isArmstrongNumber(56) -> false