How can I clean my code up to not use functions inside functions?
function toRodCase(input) {
if(!input) {
return '';
}
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
function lowerCaseFirstLetter(string) {
return string.charAt(0).toLowerCase() + string.slice(1);
}
let words = input.split(' ');
for(let i = 0; i < words.length; i++){
if(i === 0){
words[i] = lowerCaseFirstLetter(words[i]);
}else{
words[i] = 'ROD' + capitalizeFirstLetter(words[i]);
}
}
return words.join('');
}
toRodCase("Hello there stealth warrior")
Right now I have two functions within a function. How can I reduce this or is there a better way to do this?