camelCase to kebab-case
EasyUtility Functions10 min4 tests
Implement a camelToKebab function that converts a camelCase string to kebab-case.
Requirements
- Insert a hyphen before each uppercase letter and convert it to lowercase
- Handle consecutive uppercase letters gracefully
- Return an empty string for empty input
Example
camelToKebab("backgroundColor"); // "background-color"
camelToKebab("fontSize"); // "font-size"
camelToKebab("borderTopWidth"); // "border-top-width"Hints (4)
- Look for uppercase letters in the string.
- A regular expression like /[A-Z]/g can match all uppercase letters.
- Use String.prototype.replace to insert a hyphen before each match.
- Convert the entire result to lowercase at the end.
Topics
- Utility Functions
Asked at
Shopify · Stripe · Netflix
