Update flip

This commit is contained in:
Isabelle Viktoria Maciohsek
2020-10-19 18:52:11 +03:00
parent 52f9c16e73
commit 713d599f06

View File

@ -3,9 +3,10 @@ title: flip
tags: function,intermediate tags: function,intermediate
--- ---
Flip takes a function as an argument, then makes the first argument the last. Takes a function as an argument, then makes the first argument the last.
- Return a closure that takes variadic inputs, and splices the last argument to make it the first argument before applying the rest. - Use argument destructuring and a closure with variadic arguments.
- Splice the first argument, using the spread operator (`...`), to make it the last before applying the rest.
```js ```js
const flip = fn => (first, ...rest) => fn(...rest, first); const flip = fn => (first, ...rest) => fn(...rest, first);