diff --git a/lib/std.js b/lib/std.js index eb0ae8e..3d8a4d8 100644 --- a/lib/std.js +++ b/lib/std.js @@ -251,6 +251,20 @@ function addslashes(s) { ; }; +function cartesian(arr) { + return arr.reduce(function(a, b) { + return a.map(function(x) { + return b.map(function(y) { + return x.concat([y]); + }) + }).reduce(function(a, b) { + return a.concat(b); + }, []); + }, [ + [] + ]); +}; + ///////////////////////////////////////////////////////////////////////////////// // Private APIs / Utility functions ///////////////////////////////////////////////////////////////////////////////// @@ -371,4 +385,6 @@ exports.require = global.require; exports.Event = StdEvent; exports.EventableObject = StdEventableObject; + exports.alert = alert; +exports.cartesian = cartesian;