Skip to content

Instantly share code, notes, and snippets.

@mtroiani
Created December 11, 2015 23:17
Show Gist options
  • Save mtroiani/c2fd178d4c40920650e8 to your computer and use it in GitHub Desktop.
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
// 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