Skip to content

Instantly share code, notes, and snippets.

@handloomweaver
Forked from FestivalBobcats/gist:1323387
Created March 28, 2012 14:09
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 handloomweaver/2226471 to your computer and use it in GitHub Desktop.
Save handloomweaver/2226471 to your computer and use it in GitHub Desktop.
Underscore.js implementation of Cartesian Product
function cartesianProductOf(){
return _.reduce(arguments, function(mtrx, vals){
return _.reduce(vals, function(array, val){
return array.concat(
_.map(mtrx, function(row){ return row.concat(val); })
);
}, []);
}, [[]]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment