Skip to content

Instantly share code, notes, and snippets.

@omichelsen
Created August 7, 2014 20:17
Show Gist options
  • Save omichelsen/074ffaa3b52b3286afd1 to your computer and use it in GitHub Desktop.
Save omichelsen/074ffaa3b52b3286afd1 to your computer and use it in GitHub Desktop.
JS: Cartesian Product
function cartesianProductOf() {
  return Array.prototype.reduce.call(arguments, function(a, b) {
    var ret = [];
    a.forEach(function(a) {
      b.forEach(function(b) {
        ret.push(a.concat([b]));
      });
    });
    return ret;
  }, [[]]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment