Skip to content

Instantly share code, notes, and snippets.

@jremmen
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jremmen/9455293 to your computer and use it in GitHub Desktop.
Save jremmen/9455293 to your computer and use it in GitHub Desktop.
js: zip with function, takes 2 lists/arrays and zips them by mapping function (f) over each pair
zipw = function(a,b,f) {
var c = a.length < b.length ? {a:a, b:b} : {a:b, b:a};
return c.a.map(function(x,i) {
return f(x,c.b[i]);
});
}
zipw([1,2,3],[10,11,12], function(x,y) { return x + y; }); // [11,13,15]
zipw([1,2,3],[10,11,12], function(x,y) { return x * y; }); // [10,22,36]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment