Skip to content

Instantly share code, notes, and snippets.

@travissanon
Created September 23, 2017 04:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save travissanon/88c08a7593ed05e72b6c53c2b0348157 to your computer and use it in GitHub Desktop.
Save travissanon/88c08a7593ed05e72b6c53c2b0348157 to your computer and use it in GitHub Desktop.
'esversion: 6';
function translatePigLatin(str) {
var vowels = ['a', 'e', 'i', 'o', 'u'];
var string = str.split('');
var vowelFirst = false;
var vowelIndex;
vowels.map(vowel => vowel === str.charAt(0) ? vowelFirst = true : false);
for (var i = 0; i < string.length; i++) {
vowels.map(vowel => {
return string[i] === vowel ? vowelIndex = string.indexOf(string[i]) : false;
});
if (typeof(vowelIndex) === 'number') { break; }
}
if (vowelFirst === true) {
string.push('way');
} else if (typeof(vowelIndex) === 'number') {
for (var j = 0; j < vowelIndex; j++){
var index = string[j];
string.push(index);
}
string.splice(0, vowelIndex);
string.push('ay');
}
return string.join('');
}
translatePigLatin("paragraphs");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment