Skip to content

Commit a39512d

Browse files
changes
1 parent 9b5c382 commit a39512d

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

6kyus/js/convertStringToCamelCase.js

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,26 @@
55

66
function toCamelCase(str) {
77
// Determine if string includes - or underscore
8-
let returnString = ''
98
if (str.includes('-')) {
10-
returnString = str.split('-').map((word, idx) => {
11-
if (idx > 0) {
12-
return `${word.charAt(0).toUpperCase()}${word.slice(1)}`
13-
}
14-
return word
15-
})
16-
return returnString.join('')
9+
return str
10+
.split('-')
11+
.map((word, idx) => {
12+
if (idx > 0) {
13+
return `${word.charAt(0).toUpperCase()}${word.slice(1)}`
14+
}
15+
return word
16+
})
17+
.join('')
1718
} else if (str.includes('_')) {
18-
returnString = str.split('_').map((word, idx) => {
19-
if (idx > 0) {
20-
return `${word.charAt(0).toUpperCase()}${word.slice(1)}`
21-
}
22-
return word
23-
})
24-
return returnString.join('')
19+
return str
20+
.split('_')
21+
.map((word, idx) => {
22+
if (idx > 0) {
23+
return `${word.charAt(0).toUpperCase()}${word.slice(1)}`
24+
}
25+
return word
26+
})
27+
.join('')
2528
}
2629
}
2730

@@ -31,4 +34,5 @@ function toCamelCase(str) {
3134
// return string
3235
console.log(toCamelCase('the-stealth-warrior'), 'theStealthWarrior')
3336
console.log(toCamelCase('The_Templar_warrior'), 'TheTemplarWarrior')
34-
console.log(toCamelCase('The-Templar-warrior'), 'TheTemplarWarrior')
37+
console.log(toCamelCase('A_Pippi_isEvil'), 'APippiIsEvil')
38+
console.log(toCamelCase('a_pippiIsPippi'), 'aPippiIsPippi')

0 commit comments

Comments
 (0)