Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function titleCase(str) {
str = str.toLowerCase();
var split = str.split(' ');
for (var i = 0; i < split.length; i++) {
split[i] = split[i].charAt(0).toUpperCase() + split[i].slice(1);
}
var capitalizeString = split.join(' ');
return capitalizeString;
}
titleCase("I'm a little tea pot");
@jamc92

This comment has been minimized.

Copy link
Owner Author

@jamc92 jamc92 commented Apr 3, 2016

  • titleCase("I'm a little tea pot") should return a string.
  • titleCase("I'm a little tea pot") should return "I'm A Little Tea Pot".
  • titleCase("sHoRt AnD sToUt") should return "Short And Stout".
  • titleCase("HERE IS MY HANDLE HERE IS MY SPOUT") should return "Here Is My Handle Here Is My Spout".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment