Created
October 28, 2009 00:45
-
-
Save Maciek416/220116 to your computer and use it in GitHub Desktop.
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
| $R = function(a,b){ | |
| var r=[] | |
| for(var i=a;i<=b;i++) r.push(i) | |
| return r | |
| } | |
| $L = function(){ | |
| var alphabet = "abcdefghijklmnopqrstuvwxyz" | |
| var typeHint = (typeof arguments[0][0]) | |
| var f = arguments[arguments.length - 1] | |
| var out = [] | |
| rs = [] | |
| for(var i=0;i<arguments.length-1;i++){ | |
| rs.push(arguments[i]) | |
| } | |
| // argument now only contains a list of ranges | |
| var s = "" | |
| for(var i=0;i<rs.length;i++){ | |
| var id = alphabet[i] | |
| s += "for(var "+id+"=0;"+id+"<rs["+i+"].length;"+id+"++){" | |
| } | |
| s += "out.push(f(" | |
| var l = [] | |
| for(var i=0;i<rs.length;i++){ | |
| l.push(alphabet[i]) | |
| } | |
| s += l.join(",") | |
| s += "));" | |
| for(var i=0;i<rs.length;i++){ | |
| s += "}" | |
| } | |
| eval(s) | |
| return out | |
| } | |
| $L($R(1,10),function(x){ | |
| return (x%2==0)?(x*x):null | |
| }) | |
| // returns: | |
| // [0, null, 4, null, 16, null, 36, null, 64, null] | |
| $L($R(0,3), $R(0,3), function(x,y){ return x * y }) | |
| // returns: | |
| // [0, 0, 0, 0, 0, 1, 2, 3, 0, 2, 4, 6, 0, 3, 6, 9] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment