Skip to content

Instantly share code, notes, and snippets.

@jasonlotito
Created February 10, 2014 23:20
Show Gist options
  • Select an option

  • Save jasonlotito/8926251 to your computer and use it in GitHub Desktop.

Select an option

Save jasonlotito/8926251 to your computer and use it in GitHub Desktop.
Because sometimes I get bored
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!?!?!?");
}
);
@jasonlotito

Copy link
Copy Markdown
Author

Yeah, I know those loops can be improved...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment