Skip to content

Instantly share code, notes, and snippets.

@Kaeyz
Created June 13, 2018 00:30
Show Gist options
  • Save Kaeyz/a2eb52e104c38e020a0f0152fdf29707 to your computer and use it in GitHub Desktop.
Save Kaeyz/a2eb52e104c38e020a0f0152fdf29707 to your computer and use it in GitHub Desktop.
Freecodecamp challenge
function titleCase(str) {
let finalArr = [];
let finalString = "";
let lowstr = str.toLowerCase();
let spltsstr = lowstr.split(" ");
for (let count = 0; count < spltsstr.length; count++) {
let newstr = spltsstr[count]
let spltstr = newstr.split("");
let result = spltstr[0].toUpperCase();
for (let index = 1; index < spltstr.length; index++) {
result += spltstr[index]
}
finalArr.push(result)
finalString = finalArr.join(" ");
}
return finalString
}
titleCase("I'm a little tea pot");
@uzorjchibuzor
Copy link

Your code works alright, but is hard to read.
declarations on Line 5 and line 8 looks too close for comfort.
Maybe Setemi can refactor it for you if you ask him.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment