diff --git a/README.md b/README.md index 73ee28bfa..dc1bd4f18 100644 --- a/README.md +++ b/README.md @@ -436,20 +436,20 @@ Flip 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. ```js -const flip = fn => (...args) => fn(args.pop(), ...args); +const flip = fn => (first, ...rest) => fn(...rest, first); ```
Examples ```js -let a = { name: 'John Smith' }; -let b = {}; -const mergeFrom = flip(Object.assign); -let mergePerson = mergeFrom.bind(null, a); -mergePerson(b); // == b -b = {}; -Object.assign(b, a); // == b +let a = { name: 'John Smith' }; +let b = {}; +const mergeFrom = flip(Object.assign); +let mergePerson = mergeFrom.bind(null, a); +mergePerson(b); // == b +b = {}; +Object.assign(b, a); // == b ```
diff --git a/docs/index.html b/docs/index.html index 7f1126d22..89cf4a175 100644 --- a/docs/index.html +++ b/docs/index.html @@ -64,7 +64,7 @@ Promise.reso let p2 = Promise.resolve(2); let p3 = new Promise(resolve => setTimeout(resolve, 2000, 3)); Pall(p1, p2, p3).then(console.log); -

flip

Flip 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.

const flip = fn => (...args) => fn(args.pop(), ...args);
+

flip

Flip 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.

const flip = fn => (first, ...rest) => fn(...rest, first);
 
let a = { name: 'John Smith' };
 let b = {};
 const mergeFrom = flip(Object.assign);
diff --git a/snippets/flip.md b/snippets/flip.md
index 02dbe84c7..7473527ef 100644
--- a/snippets/flip.md
+++ b/snippets/flip.md
@@ -4,11 +4,11 @@ Flip 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.
 
-```js
+```js
 const flip = fn => (first, ...rest) => fn(...rest, first);
 ```
 
-```js
+```js
 let a = { name: 'John Smith' };
 let b = {};
 const mergeFrom = flip(Object.assign);