diff --git a/README.md b/README.md index a0065e55e..3ffec3b78 100644 --- a/README.md +++ b/README.md @@ -140,6 +140,7 @@
View contents +* [`average`](#average) * [`clampNumber`](#clampnumber) * [`collatz`](#collatz) * [`digitize`](#digitize) @@ -156,7 +157,9 @@ * [`isEven`](#iseven) * [`isPrime`](#isprime) * [`lcm`](#lcm) +* [`max`](#max) * [`median`](#median) +* [`min`](#min) * [`palindrome`](#palindrome) * [`percentile`](#percentile) * [`powerset`](#powerset) @@ -165,6 +168,7 @@ * [`randomNumberInRange`](#randomnumberinrange) * [`round`](#round) * [`standardDeviation`](#standarddeviation) +* [`sum`](#sum)
@@ -251,18 +255,6 @@ -### _Uncategorized_ - -
-View contents - -* [`average`](#average) -* [`max`](#max) -* [`min`](#min) -* [`sum`](#sum) - -
- ## Adapter ### call @@ -2213,6 +2205,29 @@ negate(isOdd)(1); // false ## Math +### average + +Returns the average of an of two or more numbers/arrays. + +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 = (...arr) => [].concat(...arr).reduce((acc, val) => acc + val, 0) / arr.length; +``` + +
+Examples + +```js +average([1, 2, 3]); // 2 +``` + +
+ + +[⬆ Back to top](#table-of-contents) + + ### clampNumber Clamps `num` within the inclusive range specified by the boundary values `a` and `b`. @@ -2641,6 +2656,57 @@ lcm([1, 3, 4], 5); // 60 [⬆ Back to top](#table-of-contents) +### max + +Returns the maximum value out of two or more numbers/arrays. + +Use `Math.max()` combined with the spread operator (`...`) to get the maximum value in the array. + +```js + + + + + + + + + + + + + + + + + + + + + + + + + + + + +const max = (...arr) => Math.max(...[].concat(...arr); +``` + +
+Examples + +```js +max([10, 1, 5]); // 10 +``` + +
+ + +[⬆ Back to top](#table-of-contents) + + ### median Returns the median of an array of numbers. @@ -2670,6 +2736,29 @@ median([0, 10, -2, 7]); // 3.5 [⬆ Back to top](#table-of-contents) +### min + +Returns the minimum value in an array. + +Use `Math.min()` combined with the spread operator (`...`) to get the minimum value in the array. + +```js +const min = arr => Math.min(...[].concat(...arr)); +``` + +
+Examples + +```js +min([10, 1, 5]); // 1 +``` + +
+ + +[⬆ Back to top](#table-of-contents) + + ### palindrome Returns `true` if the given string is a palindrome, `false` otherwise. @@ -2880,6 +2969,29 @@ standardDeviation([10, 2, 38, 23, 38, 23, 21], true); // 12.29899614287479 (popu +[⬆ Back to top](#table-of-contents) + + +### sum + +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`. + +```js +const sum = (...arr) => [].concat(...arr).reduce((acc, val) => acc + val, 0); +``` + +
+Examples + +```js +sum([1, 2, 3, 4]); // 10 +``` + +
+ + [⬆ Back to top](#table-of-contents) ## Media @@ -4074,102 +4186,6 @@ validateNumber('10'); // true [⬆ Back to top](#table-of-contents) -## _Uncategorized_ - -### average - -Returns the average of an of two or more numbers/arrays. - -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 = (...arr) => [].concat(...arr).reduce((acc, val) => acc + val, 0) / arr.length; -``` - -```js -average([1, 2, 3]); // 2 -``` - -
[⬆ back to top](#table-of-contents) - - -### max - -Returns the maximum value out of two or more numbers/arrays. - -Use `Math.max()` combined with the spread operator (`...`) to get the maximum value in the array. - -```js - - - - - - - - - - - - - - - - - - - - - - - - - - - -const max = (...arr) => Math.max(...[].concat(...arr); -``` - -```js -max([10, 1, 5]); // 10 -``` - -
[⬆ back to top](#table-of-contents) - - -### min - -Returns the minimum value in an array. - -Use `Math.min()` combined with the spread operator (`...`) to get the minimum value in the array. - -```js -const min = arr => Math.min(...[].concat(...arr)); -``` - -```js -min([10, 1, 5]); // 1 -``` - -
[⬆ back to top](#table-of-contents) - - -### sum - -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`. - -```js -const sum = (...arr) => [].concat(...arr).reduce((acc, val) => acc + val, 0); -``` - -```js -sum([1, 2, 3, 4]); // 10 -``` - -
[⬆ back to top](#table-of-contents) - ## Credits diff --git a/docs/index.html b/docs/index.html index 9ee9a148f..c9bb23101 100644 --- a/docs/index.html +++ b/docs/index.html @@ -185,7 +185,8 @@ negate

Math -

clampNumber +average +clampNumber collatz digitize distance @@ -201,7 +202,9 @@ isEven isPrime lcm +max median +min palindrome percentile powerset @@ -210,6 +213,7 @@ randomNumberInRange round standardDeviation +sum

Media

speechSynthesis @@ -264,12 +268,6 @@ toOrdinalSuffix validateNumber -

Uncategorized -

average -max -min -sum -
 

Adapter

call

Given a key and a set of arguments, call them when given a context. Primarily useful in composition.

@@ -1035,7 +1033,14 @@ runPromisesInSeries([() => delay(1000), () => delay(2000)]); // //executes negate(isOdd)(1); // false

Math

-

clampNumber

+

average

+

Returns the average of an of two or more numbers/arrays.

+

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 = (...arr) => [].concat(...arr).reduce((acc, val) => acc + val, 0) / arr.length;
+
+
average([1, 2, 3]); // 2
+
+

clampNumber

Clamps num within the inclusive range specified by the boundary values a and b.

If num falls within the range, return num. Otherwise, return the nearest number in the range.

@@ -1207,6 +1212,41 @@ The GCD formula uses recursion.

lcm(12, 7); // 84
 lcm([1, 3, 4], 5); // 60
 
+

max

+

Returns the maximum value out of two or more numbers/arrays.

+

Use Math.max() combined with the spread operator (...) to get the maximum value in the array.

+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+const max = (...arr) => Math.max(...[].concat(...arr);
+
+
max([10, 1, 5]); // 10
+

median

Returns the median of an array of numbers.

Find the middle of the array, use Array.sort() to sort the values. @@ -1220,6 +1260,13 @@ Return the number at the midpoint if length is odd, otherwise the a

median([5, 6, 50, 1, -5]); // 5
 median([0, 10, -2, 7]); // 3.5
 
+

min

+

Returns the minimum value in an array.

+

Use Math.min() combined with the spread operator (...) to get the minimum value in the array.

+
const min = arr => Math.min(...[].concat(...arr));
+
+
min([10, 1, 5]); // 1
+

palindrome

Returns true if the given string is a palindrome, false otherwise.

Convert string toLowerCase() and use replace() to remove non-alphanumeric characters from it. @@ -1305,6 +1352,13 @@ You can omit the second argument to get the sample standard deviation or set it

standardDeviation([10, 2, 38, 23, 38, 23, 21]); // 13.284434142114991 (sample)
 standardDeviation([10, 2, 38, 23, 38, 23, 21], true); // 12.29899614287479 (population)
 
+

sum

+

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);
+
+
sum([1, 2, 3, 4]); // 10
+

Media

speechSynthesis

Performs speech synthesis (experimental).

@@ -1810,62 +1864,6 @@ Use Number() to check if the coercion holds.

validateNumber('10'); // true
 
-

Uncategorized

-

average

-

Returns the average of an of two or more numbers/arrays.

-

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 = (...arr) => [].concat(...arr).reduce((acc, val) => acc + val, 0) / arr.length;
-
-
average([1, 2, 3]); // 2
-
-

max

-

Returns the maximum value out of two or more numbers/arrays.

-

Use Math.max() combined with the spread operator (...) to get the maximum value in the array.

-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-const max = (...arr) => Math.max(...[].concat(...arr);
-
-
max([10, 1, 5]); // 10
-
-

min

-

Returns the minimum value in an array.

-

Use Math.min() combined with the spread operator (...) to get the minimum value in the array.

-
const min = arr => Math.min(...[].concat(...arr));
-
-
min([10, 1, 5]); // 1
-
-

sum

-

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);
-
-
sum([1, 2, 3, 4]); // 10
-