Created
December 3, 2015 18:07
-
-
Save altaf933/5e018d3f8bd93d8abea4 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
// 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