diff --git a/README.md b/README.md index 87272c09c..ccf3db9f7 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,9 @@ ## Table of Contents +### Adapter +* [`spreadOver`](#spreadover) + ### Array * [`arrayGcd`](#arraygcd) * [`arrayLcm`](#arraylcm) @@ -158,6 +161,24 @@ * [`UUIDGenerator`](#uuidgenerator) * [`validateNumber`](#validatenumber) +## Adapter + +### spreadOver + +Takes a veriadic function and returns a closure that accepts an array of arguments to map to the inputs of the function. + +Use closures and the spread operator (`...`) to map the array of arguments to the inputs of the function. + +```js +const spreadOver = fn => argsArr => fn(...argsArr); +/* +const arrayMax = spreadOver(Math.max) +arrayMax([1,2,3]) // -> 3 +arrayMax([1,2,4]) // -> 4 +*/ +``` + +[⬆ back to top](#table-of-contents) ## Array ### arrayGcd diff --git a/docs/index.html b/docs/index.html index 58e9617c8..d645313ac 100644 --- a/docs/index.html +++ b/docs/index.html @@ -41,6 +41,9 @@ +

Adapter +

spreadOver +

Array

arrayGcd arrayLcm @@ -187,7 +190,18 @@ UUIDGenerator validateNumber -
 

Array

+
 

Adapter

+

spreadOver

+

Takes a veriadic function and returns a closure that accepts an array of arguments to map to the inputs of the function.

+

Use closures and the spread operator (...) to map the array of arguments to the inputs of the function.

+
const spreadOver = fn => argsArr => fn(...argsArr);
+/*
+const arrayMax = spreadOver(Math.max)
+arrayMax([1,2,3]) // -> 3
+arrayMax([1,2,4]) // -> 4
+*/
+
+

Array

arrayGcd

Calculates the greatest common denominator (gcd) of an array of numbers.

Use Array.reduce() and the gcd formula (uses recursion) to calculate the greatest common denominator of an array of numbers.