Write a function snakeToCamel(str)
that takes in a snake_cased string and returns
the string CamelCased. snake_case is a string where each word is separated with
underscores (_). CamelCase is a string where the first char of each word
is capitalized, all other characters lowercase.
Examples:
snakeToCamel('snakes_go_hiss'); // => 'SnakesGoHiss'
snakeToCamel('say_hello_world'); // => 'SayHelloWorld'
snakeToCamel('bootcamp_prep_is_cool'); // => 'BootcampPrepIsCool'
snakeToCamel('BOOtcamp_PREP_iS_cOol'); // => 'BootcampPrepIsCool'
function snakeToCamel(str) {
var newString = '';
var words = str.split('_');
for (i = 0; i < words.length; i++) {
for (j = 0; j < words.length; j++) {
if (j === 0) {
newString += words[i][j].toUpperCase();
} else {
newString += words[i][j].toLowerCase();
}
}
}
return newString;
}