Skip to content

Instantly share code, notes, and snippets.

@feltnerm
Last active August 29, 2015 14:03
Show Gist options
  • Save feltnerm/2854847e4c9dda371a2b to your computer and use it in GitHub Desktop.
Save feltnerm/2854847e4c9dda371a2b to your computer and use it in GitHub Desktop.
recursively capitalize a string that is separated by underscores:
function capitalize(s){
s = s || [''];
var titleCase = s[0].toUpperCase() + s.slice(1);
var idx = titleCase.indexOf("_");
if (idx != -1){
first = titleCase.slice(0, idx);
last = titleCase.slice(idx+1);
return first + ' ' + capitalize(last);
}
return titleCase;
}
console.log(capitalize("mark_james_feltner")); // Mark James Feltner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment