Where is a good mathematical sets implementation for JavaScript? It should include efficient implementations of intersection, union, complement, and (for bonus points) the Carte
Using Underscore's reduce method.
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); }) ); }, []); }, [[]]); }