Ad

Write a function that will have one argument which will be a string (sentence) and you have to capitalize every words first letter in that sentence. For example: if the input is "i am a javascript programmer" then the output shoud come "I Am A Javascript Programmer"

function capitalize(sentence) {
    let words = sentence.split(' ');
    const length = words.length;
    for (let i = 0; i < length; ++i) {
        words[i] = words[i][0].toUpperCase() + words[i].substr(1)
    }
    return words.join(' ');
}
console.log(capitalize("i am a javascript programmer"));