Created
December 11, 2015 07:48
-
-
Save anonymous/bd1a2b9884d68ccc5cc3 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/thetinybeaker '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: Title Case a Sentence | |
// Author: @thetinybeaker | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-title-case-a-sentence | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function titleCase(str) { | |
var myArray = str.toLowerCase().split(' '); | |
var newArray = []; | |
for (i = 0; i < myArray.length; i++) { | |
var firstLetter = myArray[i].charAt(0); | |
var capFirstLetter = myArray[i].replace(firstLetter, firstLetter.toUpperCase()); | |
newArray.push(capFirstLetter); | |
} | |
return newArray.join(' '); | |
} | |
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