Created
March 16, 2017 21:50
-
-
Save lachlan-eagling/f3da898b0d6a63093c87cb032b8d4be7 to your computer and use it in GitHub Desktop.
This file contains 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 titleCase(str) { | |
var words = str.split(" "); | |
for(var i = 0; i < words.length; i++){ | |
var temp = words[i].split(""); | |
for(var j = 0; j < temp.length; j++){ | |
if(j === 0){ | |
temp[j] = temp[j].toUpperCase(); | |
} else{ | |
temp[j] = temp[j].toLowerCase(); | |
} | |
} | |
words[i] = temp.join(""); | |
} | |
str = words.join(" "); | |
return str; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment