Menu

gitpiper

rearg javascript Code Snippet in 2024

functionintermediate

Last Updated: 6 April 2024

Creates a function that invokes the provided function with its arguments arranged according to the specified indexes.

  • Use Array.prototype.map() to reorder arguments based on indexes.
  • Use the spread operator (...) to pass the transformed arguments to fn.
const rearg = (fn, indexes) => (...args) => fn(...indexes.map(i => args[i]));
var rearged = rearg( function(a, b, c) { return [a, b, c]; }, [2, 0, 1] ); rearged('b', 'c', 'a'); // ['a', 'b', 'c']

javascript snippet similar to rearg 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! ✌️