Skip to content

Instantly share code, notes, and snippets.

@altaf933
Created December 3, 2015 18:07
Show Gist options
  • Save altaf933/5e018d3f8bd93d8abea4 to your computer and use it in GitHub Desktop.
Save altaf933/5e018d3f8bd93d8abea4 to your computer and use it in GitHub Desktop.
// Bonfire: Pig Latin
// Author: @altaf933
// Challenge: http://www.freecodecamp.com/challenges/bonfire-pig-latin
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function translate(str) {
var indeText = getIndexVowel(str);
var pigLatin='';
if(indeText==0){
pigLatin = str+"way";
}else{
pigLatin = str.substring(indeText)+""+str.substring(0,indeText)+"ay";
}
return pigLatin;
}
function getIndexVowel(str){
str = str.toLowerCase();
for(var i=0;i<str.length;i++){
if(str.charAt(i)=='a' ||str.charAt(i)=='e'||str.charAt(i)=='i'||
str.charAt(i)=='o'||str.charAt(i)=='u'){
return i;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment