diff --git a/snippets/isArmstrongNumber.md b/snippets/isArmstrongNumber.md index 4925f3dc8..d934dd715 100644 --- a/snippets/isArmstrongNumber.md +++ b/snippets/isArmstrongNumber.md @@ -5,10 +5,9 @@ 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`. ```js -const isArmstrongNumber = digits => { - let total = 0, arr = (digits+"").split(""); - arr.map(d => total += Math.pow(parseInt(d), arr.length)) - if(total === digits) return true; return false; +const isArmstrongNumber = num => { + let arr = (num+"").split(""); + return arr.reduce((a, d) => parseInt(a) + Math.pow(parseInt( d ), arr.length), 0) == num ? true : false } // isArmstrongNumber(1634) -> true