I am trying to use javascript to capitalize the words of a sentence. For example
var input = "I am not bad with javascript."
var output = "I Am Not Bad With Javascript."
I have the following codes and I can't figure out why my replace did not work.. Thank You
var loop = function(collection, callback){
// ultimate side-effects function
for (var i = 0; i < collection.length; i++){
callback(collection[i]);
}
};
var capitalizeFirstLetters = function(string) {
// have a new string
// split the string into substring
// use the loop function to find the "space"and CAP letter after
var newString = [];
var subString = string.split(' ');
loop(subString, function(word){
subString.replace(word[0], word[0].toUpperCase());
return newString.push(subString);
})
return newString.join(' ');
}