Last active
August 29, 2015 14:03
-
-
Save feltnerm/2854847e4c9dda371a2b to your computer and use it in GitHub Desktop.
recursively capitalize a string that is separated by underscores:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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