diff --git a/snippets/arrayAverage.md b/snippets/arrayAverage.md deleted file mode 100644 index 68b459b07..000000000 --- a/snippets/arrayAverage.md +++ /dev/null @@ -1,13 +0,0 @@ -### arrayAverage - -Returns the average of an array of 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 arrayAverage = arr => arr.reduce((acc, val) => acc + val, 0) / arr.length; -``` - -```js -arrayAverage([1, 2, 3]); // 2 -``` diff --git a/snippets/arrayMax.md b/snippets/arrayMax.md deleted file mode 100644 index da7bf1916..000000000 --- a/snippets/arrayMax.md +++ /dev/null @@ -1,13 +0,0 @@ -### arrayMax - -Returns the maximum value in an array. - -Use `Math.max()` combined with the spread operator (`...`) to get the maximum value in the array. - -```js -const arrayMax = arr => Math.max(...arr); -``` - -```js -arrayMax([10, 1, 5]); // 10 -``` diff --git a/snippets/arraySum.md b/snippets/arraySum.md deleted file mode 100644 index c4d5c99d2..000000000 --- a/snippets/arraySum.md +++ /dev/null @@ -1,13 +0,0 @@ -### arraySum - -Returns the sum of an array of numbers. - -Use `Array.reduce()` to add each value to an accumulator, initialized with a value of `0`. - -```js -const arraySum = arr => arr.reduce((acc, val) => acc + val, 0); -``` - -```js -arraySum([1, 2, 3, 4]); // 10 -``` diff --git a/snippets/average.md b/snippets/average.md new file mode 100644 index 000000000..6477b2535 --- /dev/null +++ b/snippets/average.md @@ -0,0 +1,13 @@ +### 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 +``` diff --git a/snippets/max.md b/snippets/max.md new file mode 100644 index 000000000..9f6bde286 --- /dev/null +++ b/snippets/max.md @@ -0,0 +1,13 @@ +### 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 +``` diff --git a/snippets/arrayMin.md b/snippets/min.md similarity index 66% rename from snippets/arrayMin.md rename to snippets/min.md index 89743bb6d..c7799694a 100644 --- a/snippets/arrayMin.md +++ b/snippets/min.md @@ -1,13 +1,13 @@ -### arrayMin +### 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 arrayMin = arr => Math.min(...arr); +const min = arr => Math.min(...[].concat(...arr)); ``` ```js -arrayMin([10, 1, 5]); // 1 +min([10, 1, 5]); // 1 ``` diff --git a/snippets/sum.md b/snippets/sum.md new file mode 100644 index 000000000..c6894b6a8 --- /dev/null +++ b/snippets/sum.md @@ -0,0 +1,13 @@ +### 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 +```