Created
December 11, 2015 23:17
-
-
Save mtroiani/c2fd178d4c40920650e8 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/mtroiani 's solution for Bonfire: Title Case a Sentence
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
// Bonfire: Check for Palindromes | |
// Author: @mtroiani | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-title-case-a-sentence | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function titleCase(str) { | |
str = str.toLowerCase(''); | |
var capStr = str.charAt(0).toUpperCase(''); | |
for (var i = 1; i < str.length; i ++) { | |
if (str.charAt(i - 1) === " ") { | |
capStr = capStr + str.charAt(i).toUpperCase(''); | |
} | |
else { | |
capStr = capStr + str.charAt(i); | |
} | |
} | |
return capStr; | |
} | |
titleCase("I'm a little tea pot"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment