Menu

gitpiper

flip javascript Code Snippet in 2023

functionintermediate

Last Updated: 1 February 2023

Takes a function as an argument, then makes the first argument the last.

  • 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.
const flip = fn => (first, ...rest) => fn(...rest, first);
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

javascript snippet similar to flip For You in February 2023

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2023 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️