Skip to content

Instantly share code, notes, and snippets.

@smnplk
Last active December 30, 2015 00:29
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save smnplk/7750086 to your computer and use it in GitHub Desktop.
var Bob = function() {
this.hey = function(message){
var respond_with = function(answer,regex_matches){
if(regex_matches)
return answer;
}
var responders = [
function() { return respond_with("Fine, be that way!", message.match(/^\s*$/)) },
function() { return respond_with("Woah, chill out!", message.match(/[A-Z]/) && message.toUpperCase() == message)},
function() { return respond_with("Sure.", message.match(/\?$/)) }];
for(var i = 0; i < responders.length; i++){
var answer = responders[i]();
if( answer !== undefined)
return answer;
}
return "Whatever";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment