Created
March 27, 2015 16:25
-
-
Save troyleach/dbf9e3625eb0c39975be to your computer and use it in GitHub Desktop.
JS funcation - code review
This file contains 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
// 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