Skip to content

Instantly share code, notes, and snippets.

@luisangelma
Last active November 19, 2015 23:05
Show Gist options
  • Select an option

  • Save luisangelma/40a96eda6e9b76b6994e to your computer and use it in GitHub Desktop.

Select an option

Save luisangelma/40a96eda6e9b76b6994e to your computer and use it in GitHub Desktop.
Call Me Maybe
var namesArray = ['angela', 'troy', 'ana', 'mark', 'amit', 'peter', 'john', 'gary', 'melissa', 'jacob'];
var dontCall = function(name) {
console.log('Not calling ' + name);
};
var call = function(name) {
console.log('Calling ' + name);
};
var sendText = function(name) {
console.log('Sending a text to ' + name);
};
var attemptCall = function(name, dontCall, call, sendText) {
var self = this;
var vowelCount = 0;
for (var i = 0; i < name.length; i++) {
if(name[i] === 'a') {
vowelCount++;
if(vowelCount >= 2) {
break;
}
}
};
if(vowelCount >= 2) {
setTimeout(function(){
console.log('Texting ' + name);
sendText(name);
}, 2000);
}
if(name.length % 2 === 0) {
setTimeout(function(){
console.log('======= Call Failed');
dontCall(name);
}, 2000);
} else {
setTimeout(function(){
console.log('======= Attempting call');
console.log('//// ' + name);
call(name);
}, 2000);
}
};
var namesIteration = function() {
for (var i = 0; i < namesArray.length; i++) {
attemptCall(namesArray[i], dontCall, call, sendText);
}
};
namesIteration();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment