Last active
August 29, 2015 13:57
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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