Created
September 23, 2017 04:00
-
-
Save travissanon/88c08a7593ed05e72b6c53c2b0348157 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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