Skip to content

Commit f6cc3a4

Browse files
optimized code
1 parent 0109c44 commit f6cc3a4

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

src/lib/toCamelCase.js

+4-7
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,11 @@ import assertString from "./util/assertString";
33
export default function toCamelCase(inputString) {
44
assertString(inputString);
55

6-
// Split the input string into words using spaces, hyphens, or underscores as separators
76
const words = inputString.split(/[\s\-_]+/);
87

9-
// Capitalize the first letter of each word except the first one
10-
for (let i = 1; i < words.length; i++) {
11-
words[i] = words[i].charAt(0).toUpperCase() + words[i].slice(1);
12-
}
8+
words.map((word) => {
9+
return word.charAt(0).toUpperCase() + word.slice(1);
10+
});
1311

14-
// Join the words back together to form the camelCase string
15-
return words.join('');
12+
return words.join("");
1613
}

0 commit comments

Comments
 (0)