Created
March 24, 2018 18:17
-
-
Save dragonza/79b58ceaa8358a2ae0a64e6079d2ed4f to your computer and use it in GitHub Desktop.
Sentence Capitalization
This file contains hidden or 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) { | |
let result = str[0].toUpperCase(); | |
for (let i = 1; i < str.length; i++) { | |
if (str[i - 1] === ' ') { | |
result += str[i].toUpperCase(); | |
} else { | |
result += str[i]; | |
} | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment