Created
September 6, 2016 19:51
-
-
Save jgresalfi/5408c601a2fd76bf3de2bd5f9aed6e8d to your computer and use it in GitHub Desktop.
FCC - Title Case A Sentence
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
var endArr = [], | |
firstCap = [], | |
finalStr = []; | |
function theChopper(arr) { | |
for (var i = 0; i < arr.length; i++) { | |
firstCap.push(arr[i].charAt(0).toUpperCase()); | |
endArr.push(arr[i].slice(1)); | |
} | |
} | |
function theJoiner(arr1, arr2) { | |
var j = 0; | |
for (var i = 0; i < arr1.length; i++) { | |
finalStr.push(arr1[i] + arr2[j]); | |
j++; | |
} | |
} | |
function titleCase(str) { | |
var strArr = str.toLowerCase().split(" "); | |
theChopper(strArr); | |
theJoiner(firstCap, endArr); | |
return finalStr.join(" "); | |
} | |
titleCase("He's his own Granpa"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment