Skip to content

Instantly share code, notes, and snippets.

@Luke-Rogerson
Created December 16, 2018 18:58
Show Gist options
  • Save Luke-Rogerson/8dd3c21b1bd7798cc96e76c0e9e3b332 to your computer and use it in GitHub Desktop.
Save Luke-Rogerson/8dd3c21b1bd7798cc96e76c0e9e3b332 to your computer and use it in GitHub Desktop.
Write a function that accepts a string. The function should capitalize the first letter of each word in the string then return the capitalized string.
function capitalize(str) {
const capitalizedSentence = [];
for (let word of str.split(' ')) {
const capitalizedWord = word[0].toUpperCase() + word.slice(1);
capitalizedSentence.push(capitalizedWord);
}
return capitalizedSentence.join(' ');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment