Update isArmstrongNumber.md
This commit is contained in:
@ -5,8 +5,8 @@ Checks if the given number is an armstrong number or not.
|
|||||||
Convert the given number into 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`.
|
Convert the given number into 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`.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const isArmstrongNumber = digits => ( arr => arr.reduce( ( a, d ) => a + Math.pow( parseInt( d ), arr.length ), 0 ) == digits ? true : false )( ( digits+'' ).split( '' ) )
|
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(1634) -> true
|
||||||
// isArmstrongNumber(371) -> true
|
// isArmstrongNumber(371) -> true
|
||||||
// isArmstrongNumber(56) -> false
|
// isArmstrongNumber(56) -> false
|
||||||
|
|||||||
Reference in New Issue
Block a user