Skip to content

Instantly share code, notes, and snippets.

Created December 12, 2015 00:38
Show Gist options
  • Save anonymous/29831a6b9cef7214daa7 to your computer and use it in GitHub Desktop.
Save anonymous/29831a6b9cef7214daa7 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/tylerl-uxai 's solution for Bonfire: Pig Latin
// 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