Created
December 16, 2018 18:58
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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