Created
June 13, 2018 00:30
-
-
Save Kaeyz/a2eb52e104c38e020a0f0152fdf29707 to your computer and use it in GitHub Desktop.
Freecodecamp challenge
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) { | |
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"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.