Skip to content

Instantly share code, notes, and snippets.

  • Save anonymous/ee2710f6d3065551f041 to your computer and use it in GitHub Desktop.
Save anonymous/ee2710f6d3065551f041 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/kachilero 's solution for Bonfire: Title Case a Sentence
// Bonfire: Title Case a Sentence
// Author: @kachilero
// Challenge: http://www.freecodecamp.com/challenges/bonfire-title-case-a-sentence?solution=function%20titleCase(str)%20%7B%0A%20%20strArray%20%3D%20str.toLowerCase().split(%27%20%27)%3B%0A%20%20for%20(var%20i%20%3D%200%3B%20i%20%3C%20strArray.length%3B%20i%2B%2B)%20%7B%0A%20%20%20%20var%20j%20%3D%20strArray%5Bi%5D.charAt().toUpperCase()%3B%0A%20%20%20%20strArray%5Bi%5D%20%3D%20j%20%2B%20strArray%5Bi%5D.substr(1)%3B%0A%20%20%7D%0A%20%20return%20strArray.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) {
strArray = str.toLowerCase().split(' ');
for (var i = 0; i < strArray.length; i++) {
var j = strArray[i].charAt().toUpperCase();
strArray[i] = j + strArray[i].substr(1);
}
return strArray.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