//codewars:Convert string to camel case
function toCamelCase(str){
//console.log(str, 'testing')
if(str === ''){
return ''
} else {
let containmentArea = []
let splitString = str.replace(/[^A-Z0-9]/ig, "_").split("_")
//[ 'the', 'stealth', 'warrior' ]
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('')
}
}
def to_camel_case(text):
if text == '':
return text
for i in text:
if i == '-' or i == '_':
text = text.replace(text[text.index(i):text.index(i)+2], text[text.index(i)+1].upper(), 1)
return text
const camelCase = (string) => {
function camelize(str) {
return str
.replace(/(?:^w|[A-Z]|w)/g, function(word, index) {
return index === 0 ? word.toLowerCase() : word.toUpperCase();
})
.replace(/s+/g, "");
}
const newText = camelize(string);
return newText
};
const camalize = function camalize(str) {
return str.toLowerCase().replace(/[^a-zA-Z0-9]+(.)/g, (m, chr) => chr.toUpperCase());
}
function toCamelCase(str){
let strArray;
if(str === ''){
return ''
}
if(str.indexOf('-') !== -1){
strArray = str.split('-')
}else{
strArray = str.split('_')
}
let capitalString = strArray[0]
for(let i=1; i<strArray.length;i++){
capitalString+= capitalize(strArray[i])
}
return capitalString
}
let capitalize = (str) =>{
return str[0].toUpperCase()+str.slice(1)
}
convert camel case to string