Skip to content

Instantly share code, notes, and snippets.

@devilshaircut
Last active August 29, 2015 14:20
Show Gist options
  • Save devilshaircut/dc132d270cd103aa3b5d to your computer and use it in GitHub Desktop.
Save devilshaircut/dc132d270cd103aa3b5d to your computer and use it in GitHub Desktop.
Two letter words?
var alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"];
var vowels = ["a", "e", "i", "o", "u", "y", "h"];
var numberOfWords = 0;
var words = [];
var populatePossibilities = function(base) {
var newPossibilities = [];
var baseLength = base.length;
for (var i=0; i < baseLength; i++) {
for (var j=0; j < baseLength; j++) {
newPossibilities.push(base[i] + base[j]);
}
}
return newPossibilities;
};
var possibilities = populatePossibilities(alphabet);
var isVowel = function(testLetter, testVowels) {
var vowelLength = testVowels.length;
for (var i=0; i < vowelLength; i++) {
if ( testVowels[i] === testLetter ) {
return true;
}
}
return false;
};
var isUnique = function(testWord, checkList) {
var checkListLength = checkList.length;
for (var i=0; i < checkListLength; i++) {
if ( checkList[i] === testWord ) {
return false;
}
}
return true;
};
var checkStrings = function(wordsArray, testVowels) {
var wordsLength = wordsArray.length;
for (var i=0; i < wordsLength; i++) {
if ( isUnique(wordsArray[i], words) ) {
var stringAsArray = wordsArray[i].split("");
if ( isVowel(stringAsArray[0], testVowels) || isVowel(stringAsArray[1], testVowels) ) {
numberOfWords++;
words.push(wordsArray[i]);
};
}
}
return words;
};
checkStrings(possibilities, vowels);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment