diff --git a/README.md b/README.md index 68e24214e..4591b60e6 100644 --- a/README.md +++ b/README.md @@ -3340,7 +3340,7 @@ standardDeviation([10, 2, 38, 23, 38, 23, 21], true); // 12.29899614287479 (popu ### sum -Returns the sum of an of two or more numbers/arrays. +Returns the sum of two or more numbers/arrays. Use `Array.reduce()` to add each value to an accumulator, initialized with a value of `0`. diff --git a/docs/index.html b/docs/index.html index 92f670e5d..a3e69f2df 100644 --- a/docs/index.html +++ b/docs/index.html @@ -732,7 +732,7 @@ solveRPN('2 3 ^'); //8 };
standardDeviation([10, 2, 38, 23, 38, 23, 21]); // 13.284434142114991 (sample)
standardDeviation([10, 2, 38, 23, 38, 23, 21], true); // 12.29899614287479 (population)
-Returns the sum of an of two or more numbers/arrays.
Use Array.reduce() to add each value to an accumulator, initialized with a value of 0.
const sum = (...arr) => [].concat(...arr).reduce((acc, val) => acc + val, 0);
+Returns the sum of two or more numbers/arrays.
Use Array.reduce() to add each value to an accumulator, initialized with a value of 0.
const sum = (...arr) => [].concat(...arr).reduce((acc, val) => acc + val, 0);
sum([1, 2, 3, 4]); // 10
Returns the sum of the powers of all the numbers from start to end (both inclusive).
Use Array.fill() to create an array of all the numbers in the target range, Array.map() and the exponent operator (**) to raise them to power and Array.reduce() to add them together. Omit the second argument, power, to use a default power of 2. Omit the third argument, start, to use a default starting value of 1.
const sumPower = (end, power = 2, start = 1) =>
Array(end + 1 - start)