Skip to content

Instantly share code, notes, and snippets.

@minsooshin
Last active November 22, 2015 04:01
Show Gist options
  • Save minsooshin/b5366f6692d144078406 to your computer and use it in GitHub Desktop.
Save minsooshin/b5366f6692d144078406 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/minsooshin 's solution for Bonfire: Pig Latin
// 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