update snippets 62-78

This commit is contained in:
Stefan Feješ
2017-12-25 14:23:06 +01:00
parent 700e6edfe7
commit 038df28ca5
16 changed files with 78 additions and 33 deletions

View File

@ -5,9 +5,12 @@ 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`.
```js
const isArmstrongNumber = digits =>
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
```
```js
isArmstrongNumber(1634) -> true
isArmstrongNumber(371) -> true
isArmstrongNumber(56) -> false
```