Created
March 3, 2016 12:17
-
-
Save srkama/dd6f130f88910050ede3 to your computer and use it in GitHub Desktop.
freecodecamp problem
This file contains hidden or 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 spinalCase(str) { | |
| newString=str[0]; | |
| for (i=1;i<str.length;i++) { | |
| console.log(str[i]); | |
| if (str[i] == ' ' || str[i] == '_') { | |
| if (newString[newString.length-1]!='-') { | |
| newString+="-"; | |
| } | |
| } else if(str[i].toUpperCase()==str[i] && str[i]!=="-") { | |
| if (newString[newString.length-1]!='-') { | |
| newString+="-"; | |
| } | |
| newString+=str[i]; | |
| } else { | |
| newString+=str[i]; | |
| } | |
| } | |
| // "It's such a fine line between stupid, and clever." | |
| // --David St. Hubbins | |
| return newString.toLowerCase(); | |
| } | |
| spinalCase('This Is Spinal Tap'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment