Skip to content

Instantly share code, notes, and snippets.

@smnplk smnplk/Bob.js
Last active Dec 30, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.