Skip to content

Instantly share code, notes, and snippets.

Created December 3, 2015 16:33
Show Gist options
  • Save anonymous/a68a0e3d48e55bf12892 to your computer and use it in GitHub Desktop.
Save anonymous/a68a0e3d48e55bf12892 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/narshe1412 's solution for Bonfire: Title Case a Sentence
// Bonfire: Title Case a Sentence
// Author: @narshe1412
// 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 strtemp = str.toLowerCase().split(" ");
for (var i = 0; i < strtemp.length; i++){
var firstLetter = strtemp[i].charAt(0).toUpperCase();
strtemp[i] = firstLetter + strtemp[i].substring(1);
}
return strtemp.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