Skip to content

Instantly share code, notes, and snippets.

@jgresalfi
Created September 6, 2016 19:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgresalfi/5408c601a2fd76bf3de2bd5f9aed6e8d to your computer and use it in GitHub Desktop.
Save jgresalfi/5408c601a2fd76bf3de2bd5f9aed6e8d to your computer and use it in GitHub Desktop.
FCC - Title Case A Sentence
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