From 520c9b669993c71ba4873547885a39b2f6f1c062 Mon Sep 17 00:00:00 2001 From: 30secondsofcode <30secondsofcode@gmail.com> Date: Thu, 9 Aug 2018 06:50:34 +0000 Subject: [PATCH] Travis build: 204 --- README.md | 2 +- docs/math.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0af57d51d..cd1c4ade7 100644 --- a/README.md +++ b/README.md @@ -5181,7 +5181,7 @@ Returns the average of two or more numbers. Use `Array.reduce()` to add each value to an accumulator, initialized with a value of `0`, divide by the `length` of the array. ```js -const average = (...nums) => [...nums].reduce((acc, val) => acc + val, 0) / nums.length; +const average = (...nums) => nums.reduce((acc, val) => acc + val, 0) / nums.length; ```
diff --git a/docs/math.html b/docs/math.html index ee8dfb243..6943efdb1 100644 --- a/docs/math.html +++ b/docs/math.html @@ -81,7 +81,7 @@ }, false); }

logo 30 seconds of code Curated collection of useful JavaScript snippets that you can understand in 30 seconds or less.

 

Math

approximatelyEqual

Checks if two numbers are approximately equal to each other.

Use Math.abs() to compare the absolute difference of the two values to epsilon. Omit the third parameter, epsilon, to use a default value of 0.001.

const approximatelyEqual = (v1, v2, epsilon = 0.001) => Math.abs(v1 - v2) < epsilon;
 
approximatelyEqual(Math.PI / 2.0, 1.5708); // true
-

average

Returns the average of two or more numbers.

Use Array.reduce() to add each value to an accumulator, initialized with a value of 0, divide by the length of the array.

const average = (...nums) => [...nums].reduce((acc, val) => acc + val, 0) / nums.length;
+

average

Returns the average of two or more numbers.

Use Array.reduce() to add each value to an accumulator, initialized with a value of 0, divide by the length of the array.

const average = (...nums) => nums.reduce((acc, val) => acc + val, 0) / nums.length;
 
average(...[1, 2, 3]); // 2
 average(1, 2, 3); // 2
 

averageBy

Returns the average of an array, after mapping each element to a value using the provided function.

Use Array.map() to map each element to the value returned by fn, Array.reduce() to add each value to an accumulator, initialized with a value of 0, divide by the length of the array.

const averageBy = (arr, fn) =>