Last active
November 22, 2015 04:01
-
-
Save minsooshin/b5366f6692d144078406 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/minsooshin 's solution for Bonfire: Pig Latin
This file contains hidden or 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: @minsooshin | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-pig-latin | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function translate(str) { | |
var vowelReg = /^[aeiou]/i, | |
index = []; | |
if ((vowelReg).test(str)) { | |
str = str + 'way'; | |
} else { | |
for (var i = 0; i < str.length; i++) { | |
if (vowelReg.test(str[i])) index.push(i); | |
} | |
str = str.substr(index[0], str.length) + str.substr(0, index[0]) + 'ay'; | |
} | |
return str; | |
} | |
translate("consonant"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment