Skip to content

Instantly share code, notes, and snippets.

  • Save anonymous/ca7fbc9ed1b12846bbf4 to your computer and use it in GitHub Desktop.
Save anonymous/ca7fbc9ed1b12846bbf4 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/v3rse 's solution for Bonfire: Title Case a Sentence
// Bonfire: Title Case a Sentence
// Author: @v3rse
// Challenge: http://www.freecodecamp.com/challenges/bonfire-title-case-a-sentence?solution=function%20titleCase(str)%20%7B%0A%20%20%2F%2Fsplit%20it%20up%20to%20play%20with%0A%20%20var%20strArray%20%3D%20str.split(%22%20%22)%3B%0A%20%20%0A%20%20%2F%2Falter%20values%0A%20%20return%20strArray.map(function(val)%7B%0A%20%20%20%20%2F%2Fput%20UpperCase%20in%20the%20first%20position%0A%20%20%20%20console.log(val.charAt(0).toUpperCase()%20%2B%20val.slice(1).toLowerCase())%3B%0A%20%20%20%20return%20val.charAt(0).toUpperCase()%20%2B%20val.slice(1).toLowerCase()%3B%0A%20%20%7D).join(%22%20%22)%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) {
//split it up to play with
var strArray = str.split(" ");
//alter values
return strArray.map(function(val){
//put UpperCase in the first position
console.log(val.charAt(0).toUpperCase() + val.slice(1).toLowerCase());
return val.charAt(0).toUpperCase() + val.slice(1).toLowerCase();
}).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