Travis build: 1469

This commit is contained in:
30secondsofcode
2018-01-28 13:05:40 +00:00
parent f74c10be60
commit ca7c242d24
2 changed files with 50 additions and 1 deletions

View File

@ -86,6 +86,7 @@ average(1, 2, 3);
* [`pipeAsyncFunctions`](#pipeasyncfunctions)
* [`pipeFunctions`](#pipefunctions)
* [`promisify`](#promisify)
* [`rearg`](#rearg)
* [`spreadOver`](#spreadover)
* [`unary`](#unary)
@ -672,6 +673,40 @@ delay(2000).then(() => console.log('Hi!')); // // Promise resolves after 2s
<br>[⬆ Back to top](#table-of-contents)
### rearg
Creates a function that invokes the provided function with its arguments arranged according to the specified indexes.
Use `Array.reduce()` and `Array.indexOf()` to reorder arguments based on `indexes` in combination with the spread operator (`...`) to pass the transformed arguments to `fn`.
```js
const rearg = (fn, indexes) => (...args) =>
fn(
...args.reduce(
(acc, val, i) => ((acc[indexes.indexOf(i)] = val), acc),
Array.from({ length: indexes.length })
)
);
```
<details>
<summary>Examples</summary>
```js
var rearged = rearg(
function(a, b, c) {
return [a, b, c];
},
[2, 0, 1]
);
rearged('b', 'c', 'a'); // ['a', 'b', 'c']
```
</details>
<br>[⬆ Back to top](#table-of-contents)
### spreadOver
Takes a variadic function and returns a closure that accepts an array of arguments to map to the inputs of the function.

File diff suppressed because one or more lines are too long