Created
December 12, 2015 00:38
-
-
Save anonymous/29831a6b9cef7214daa7 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/tylerl-uxai '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: @tylerl-uxai | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-pig-latin | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function translate(str) { | |
var regex = /[aeiou]/gi; | |
if (str[0].match(regex)){ | |
return str + "way"; | |
} else if (str[1].match(regex)){ | |
return str.slice(1) + str.charAt(0) + "ay"; | |
} else { | |
return str.slice(2)+str.charAt(0)+str.charAt(1)+"ay"; | |
} | |
} | |
translate("consonant"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment