Coding Challenge - #8: Convert Kebab Case

Write a function kebabToCamel(str) that converts a kebab-case string into camelCase. For example, kebabToCamel('font-size-adjust') should return 'fontSizeAdjust' and kebabToCamel('display') should return 'display'.

function kebabToCamel(str) {
  // Your code here
}

Rules:

  • Assume all input characters are lowercase letters and hyphens.
  • Do not use external libraries.
  • Preserve strings with no hyphens as-is.

Post your solution as a reply. Answer goes up in about a day.

function kebabToCamel(str) {
  return str.split('-').map((word, i) =>
    i === 0 ? word : word[0].toUpperCase() + word.slice(1)
  ).join('');
}

console.log(kebabToCamel('font-size-adjust')); // fontSizeAdjust
console.log(kebabToCamel('display'));          // display

This also preserves strings without hyphens as-is.

okay so we’ve got a first entry on the board! love seeing the different approaches people take to these kinds of string transforms. the solution drops later today!

The variety in string manipulation is always fascinating. I wonder if anyone considered the performance implications for very long strings.