From acbb3903fa2d62f4b312004cf6933453bc903576 Mon Sep 17 00:00:00 2001 From: atomiks Date: Mon, 1 Jan 2018 04:40:03 +1100 Subject: [PATCH 1/3] Use exponent ** operator over Math.pow --- snippets/isArmstrongNumber.md | 2 +- snippets/standardDeviation.md | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/snippets/isArmstrongNumber.md b/snippets/isArmstrongNumber.md index af6ba739b..ab6d7a6e0 100644 --- a/snippets/isArmstrongNumber.md +++ b/snippets/isArmstrongNumber.md @@ -6,7 +6,7 @@ Convert the given number into an array of digits. Use `Math.pow()` to get the ap ```js const isArmstrongNumber = digits => - (arr => arr.reduce((a, d) => a + Math.pow(parseInt(d), arr.length), 0) == digits)( + (arr => arr.reduce((a, d) => a + parseInt(d) ** arr.length, 0) == digits)( (digits + '').split('') ); ``` diff --git a/snippets/standardDeviation.md b/snippets/standardDeviation.md index fe26f58f2..09d1d7981 100644 --- a/snippets/standardDeviation.md +++ b/snippets/standardDeviation.md @@ -10,9 +10,7 @@ You can omit the second argument to get the sample standard deviation or set it const standardDeviation = (arr, usePopulation = false) => { const mean = arr.reduce((acc, val) => acc + val, 0) / arr.length; return Math.sqrt( - arr - .reduce((acc, val) => acc.concat(Math.pow(val - mean, 2)), []) - .reduce((acc, val) => acc + val, 0) / + arr.reduce((acc, val) => acc.concat((val - mean) ** 2), []).reduce((acc, val) => acc + val, 0) / (arr.length - (usePopulation ? 0 : 1)) ); }; From 0970fcd136b9ed9ae6f926e3de09d1e135453cd1 Mon Sep 17 00:00:00 2001 From: atomiks Date: Mon, 1 Jan 2018 04:40:59 +1100 Subject: [PATCH 2/3] fix description --- snippets/isArmstrongNumber.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/isArmstrongNumber.md b/snippets/isArmstrongNumber.md index ab6d7a6e0..effb58e20 100644 --- a/snippets/isArmstrongNumber.md +++ b/snippets/isArmstrongNumber.md @@ -2,7 +2,7 @@ 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`. +Convert the given number into an array of digits. Use the exponent `**` operator 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 => From 06cd4cbbc74f77f4ba2510dab8de05b0b667d547 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Sun, 31 Dec 2017 19:42:21 +0200 Subject: [PATCH 3/3] Update isArmstrongNumber.md --- snippets/isArmstrongNumber.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/isArmstrongNumber.md b/snippets/isArmstrongNumber.md index effb58e20..8f8ae8ed3 100644 --- a/snippets/isArmstrongNumber.md +++ b/snippets/isArmstrongNumber.md @@ -2,7 +2,7 @@ Checks if the given number is an Armstrong number or not. -Convert the given number into an array of digits. Use the exponent `**` operator 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 an array of digits. Use the exponent operator (`**`) 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 =>