Skip to content

Instantly share code, notes, and snippets.

@troyleach
Created March 27, 2015 16:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save troyleach/dbf9e3625eb0c39975be to your computer and use it in GitHub Desktop.
Save troyleach/dbf9e3625eb0c39975be to your computer and use it in GitHub Desktop.
JS funcation - code review
// Write a function translate() that will translate a text into "rövarspråket".
// That is, double every consonant and place an occurrence of "o" in between.
// For example, translate("this is fun") should return the string "tothohisos isos fofunon".
var character = []
function translate(sentence) {
var new_str = sentence.split("");
for (var i = 0; i < new_str.length; i++) {
if (new_str[i].match(/[aeiou | AEIOU]/)) {
character.push(new_str[i]);
} else if (new_str[i].match(/\s/)) {
character.push(" ");
} else if (!new_str[i].match(/[aeiou]/)) {
character.push(new_str[i] + "o" + new_str[i]);
}
}
return character.join("");
}
console.log(translate('this is fun'));
console.log(translate('I am starting to like javascript'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment