Coding Challenge - #27: Convert Case Style

Write a function toCamelCase(str) that converts a kebab-case or snake_case string into camelCase. For example, toCamelCase('font-size') and toCamelCase('font_size') should both return 'fontSize', while toCamelCase('background_color_name') should return 'backgroundColorName'.

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

Rules:

  • Must handle both hyphens (-) and underscores (_) as delimiters
  • Do not capitalize the first character of the string
  • Return the converted string

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

Hmm, the challenge seems straightforward. But what happens if a key already has a camelCase segment in it? Like some-CSSProperty? Does it become someCssProperty or someCSSProperty? The rules don’t specify.