Travis build: 1469
This commit is contained in:
35
README.md
35
README.md
@ -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
Reference in New Issue
Block a user