var anneWork = function (initialTerm) {
//initialise array to hold variations
var variations = [],
alphabet = function () {
return _.map(_.range('a'.charCodeAt(0), 'z'.charCodeAt(0)), function (c) {
return String.fromCharCode(c);
});
},
vowels = ['a', 'e', 'i', 'o', 'u'],
consonants = _.difference(alphabet(), vowels);
//for each vowel
for (var i = 0; i < vowels.length; i++) {
//"o"
var currentVowel = vowels[i];
//"oo"
var pairOfCurrentVowel = currentVowel + currentVowel;
for (var characterInInitialTerm = 0; characterInInitialTerm < initialTerm.length; characterInInitialTerm++) {
//initialTerm = "bool";
//"o"
var currentCharacter = initialTerm[characterInInitialTerm];
//"o"
var nextCharacter = initialTerm[characterInInitialTerm + 1];
//"oo"
var currentAndNext = currentCharacter + nextCharacter;
if (currentAndNext === pairOfCurrentVowel) {
var possibleConsonant = initialTerm[characterInInitialTerm + 2];
var possibleNextConsonant = initialTerm[characterInInitialTerm + 3];
if (possibleConsonant === possibleNextConsonant && _.contains(consonants, possibleConsonant)) {
var additionalTermVariationDoubleConsonant = initialTerm.slice(characterInInitialTerm + 3, 1);
variations.push(additionalTermVariationDoubleConsonant);
} else {
var additionalTermVariationSingleConsonant = initialTerm.slice(characterInInitialTerm + 2 + 1, 0);
variations.push(additionalTermVariationSingleConsonant);
}
}
}
}
return variations;
};
console.log(anneWork('bool'));
//for each character in initialTerm, if that character and the next is equal to the current vowel pair, get the...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.