Menu

gitpiper

juxt javascript Code Snippet in 2024

functionadvanced

Last Updated: 17 July 2024

Takes several functions as argument and returns a function that is the juxtaposition of those functions.

  • Use Array.prototype.map() to return a fn that can take a variable number of args.
  • When fn is called, return an array containing the result of applying each fn to the args.
const juxt = (...fns) => (...args) => [...fns].map(fn => [...args].map(fn));
juxt( x => x + 1, x => x - 1, x => x * 10 )(1, 2, 3); // [[2, 3, 4], [0, 1, 2], [10, 20, 30]] juxt( s => s.length, s => s.split(' ').join('-') )('30 seconds of code'); // [[18], ['30-seconds-of-code']]

javascript snippet similar to juxt For You in July 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! ✌️