cf.completefrontend

Write the codeMedium

Write camelCase(text) and kebabCase(text) to convert between naming styles.

Both functions accept text in any mix of styles. Spaces, -, and _ mark word boundaries, and so does a lowercase letter followed by a capital, as in backgroundColor. A run of capitals is one word: XMLHttpRequest is xml, http, and request.

camelCase lowercases the first word and capitalizes the others, which means an uppercase first letter and a lowercase rest, so FOO_BAR becomes fooBar. kebabCase lowercases every word and joins them with -.

Digits stay with the word they follow, and accented letters count as letters.

Write this
function camelCase(text) {
  // your code
}
 
function kebabCase(text) {
  // your code
}
 
// camelCase("background-color"); // "backgroundColor"
// camelCase("FOO_BAR");          // "fooBar"
// kebabCase("backgroundColor");  // "background-color"
// kebabCase("XMLHttpRequest");   // "xml-http-request"
// kebabCase("version2Beta");     // "version2-beta"

Solve it in the editor, with tests

The answer

Write it yourself first. Then compare it with a reference solution and the checks it passes.

Checking your sign-in…