Created
February 10, 2014 23:20
-
-
Save jasonlotito/8926251 to your computer and use it in GitHub Desktop.
Because sometimes I get bored
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
| function match(){ | |
| console.log(arguments); | |
| var test = arguments[0]; | |
| for(var x = 1; x < arguments.length; x++){ | |
| var foundMatch = true; | |
| var val = arguments[x]; | |
| if(typeof test === "object"){ | |
| for(var c in test){ | |
| if(test[c] !== val[c]){ | |
| foundMatch = false; | |
| break; | |
| } | |
| } | |
| } else if (test === undefined){ | |
| foundMatch = true; | |
| } | |
| if(foundMatch){ | |
| return arguments[++x](val); | |
| } | |
| } | |
| } | |
| var __ = undefined; | |
| var x = {ok:true}; | |
| var ok = function() { | |
| console.log("OK!"); | |
| }; | |
| var notok = function() { | |
| console.log("NOT OK!"); | |
| }; | |
| match(x, | |
| {ok: true}, ok, | |
| {ok: false}, notok, | |
| __, function(){ | |
| console.log("This is incredibly odd!?!?!?"); | |
| } | |
| ); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yeah, I know those loops can be improved...