Skip to content

Instantly share code, notes, and snippets.

@elephantsofneptune
Forked from noshaf/PigLatin.js
Created May 14, 2017 08:44
Show Gist options
  • Save elephantsofneptune/27a1e7e0da03c1fcf496d2bcfa8dd092 to your computer and use it in GitHub Desktop.
Save elephantsofneptune/27a1e7e0da03c1fcf496d2bcfa8dd092 to your computer and use it in GitHub Desktop.
Pig Latin Javascript
var translate = function(word) {
var array = word.split('');
var vowels = ['a','e','i','o','u'];
var newWord = '';
for(var i = 0; i < vowels.length-1; i++) {
for(var y = 0; y < word.length-1; y++) {
if(word[y] === vowels[i]) {
for(var x = y; x < word.length; x++){
newWord = newWord + word[x];
}
for(var n = 0; n < y; n++){
newWord = newWord + word[n];
}
return newWord + "ay";
}
}
}
}
translate("apple");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment