Skip to content

Instantly share code, notes, and snippets.

@codebubb
Created November 13, 2015 23:34
Show Gist options
  • Save codebubb/01473bd1b0136d37b2e6 to your computer and use it in GitHub Desktop.
Save codebubb/01473bd1b0136d37b2e6 to your computer and use it in GitHub Desktop.
// Bonfire: Title Case a Sentence
// Author: @codebubb
// Challenge: http://www.freecodecamp.com/challenges/bonfire-title-case-a-sentence?solution=function%20titleCase(str)%20%7B%0A%20%20return%20str.toLowerCase().split(%27%20%27).map(function(word)%7B%0A%20%20%20%20return%20word.charAt(0).toUpperCase()%20%2B%20word.substring(1%2C%20word.length)%3B%0A%20%20%7D).join(%27%20%27)%3B%0A%7D%0A%0AtitleCase(%22I%27m%20a%20little%20tea%20pot%22)%3B%0A
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function titleCase(str) {
return str.toLowerCase().split(' ').map(function(word){
return word.charAt(0).toUpperCase() + word.substring(1, word.length);
}).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