Created
September 16, 2020 03:23
-
-
Save hebertcisco/c31ffe4adec67722dc5b7aa98180a720 to your computer and use it in GitHub Desktop.
Convert string to camel case" algorithm, CodeWars
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 toCamelCase(str){ | |
if(str === ''){ | |
return '' | |
} else { | |
let containmentArea = [] | |
let splitString = str.replace(/[^A-Z0-9]/ig, "_").split("_") | |
let firstElement = containmentArea.push( splitString.splice(0,1) ) | |
for(let word in splitString){ | |
let splitWords = splitString[word].split('') | |
let capitalLetter = splitWords[0].toUpperCase() | |
splitWords.splice(0,1, capitalLetter) | |
let joinedWord = splitWords.join('') | |
containmentArea.push(joinedWord) | |
let newSentence = containmentArea.join('') | |
} | |
return containmentArea.join('') | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment