This file contains 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
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