From 67ec42411bb2cdaca662aa14dbd5c37f5e81aaad Mon Sep 17 00:00:00 2001 From: Arjun Mahishi Date: Wed, 20 Dec 2017 12:30:56 +0530 Subject: [PATCH] Updated function with help from @skatcat31 --- snippets/isArmstrongNumber.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/snippets/isArmstrongNumber.md b/snippets/isArmstrongNumber.md index d934dd715..2b9f2970a 100644 --- a/snippets/isArmstrongNumber.md +++ b/snippets/isArmstrongNumber.md @@ -5,10 +5,7 @@ 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 = num => { - let arr = (num+"").split(""); - return arr.reduce((a, d) => parseInt(a) + Math.pow(parseInt( d ), arr.length), 0) == num ? true : 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