Menu

gitpiper

flip javascript Code Snippet in 2024

functionintermediate

Last Updated: 21 April 2024

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 April 2024

Subscribe to our Newsletter

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

© 2024 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! ✌️