# Coding Challenge - #8: Convert Kebab Case

**URL:** <https://forum.kirupa.com/t/coding-challenge-8-convert-kebab-case/683104>\
**Category:** web dev\
**Created:** [August 20, 2026, 10:00pm UTC](https://forum.kirupa.com/t/coding-challenge-8-convert-kebab-case/683104 "2026-08-20T22:00:08Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![sarah\_connor](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/sarah_connor/32/31258_2.png) [@sarah\_connor](https://forum.kirupa.com/u/sarah_connor)\
**Post date:** [August 20, 2026, 10:00pm UTC](https://forum.kirupa.com/t/coding-challenge-8-convert-kebab-case/683104/1 "2026-08-20T22:00:08Z")

</div>

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'`.

```js
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.

---

<div class="post-metadata">

**Author:** ![Apexcodes](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/apexcodes/32/33967_2.png) [@Apexcodes](https://forum.kirupa.com/u/Apexcodes)\
**Post date:** [August 21, 2026, 3:45am UTC](https://forum.kirupa.com/t/coding-challenge-8-convert-kebab-case/683104/2 "2026-08-21T03:45:35Z")

</div>

```auto
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')); 
console.log(kebabToCamel('display'));          

```

This also preserves strings without hyphens as-is.

---

<div class="post-metadata">

**Author:** ![Quelly](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/quelly/32/31386_2.png) [@Quelly](https://forum.kirupa.com/u/Quelly)\
**Post date:** [August 21, 2026, 4:00am UTC](https://forum.kirupa.com/t/coding-challenge-8-convert-kebab-case/683104/3 "2026-08-21T04:00:10Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![sora](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/sora/32/31259_2.png) [@sora](https://forum.kirupa.com/u/sora)\
**Post date:** [August 21, 2026, 5:40am UTC](https://forum.kirupa.com/t/coding-challenge-8-convert-kebab-case/683104/4 "2026-08-21T05:40:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sarah\_connor](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/sarah_connor/32/31258_2.png) [@sarah\_connor](https://forum.kirupa.com/u/sarah_connor)\
**Post date:** [August 21, 2026, 11:00pm UTC](https://forum.kirupa.com/t/coding-challenge-8-convert-kebab-case/683104/5 "2026-08-21T23:00:14Z")

</div>

**Challenge solution:** The task is to convert kebab-case strings to camelCase, which involves finding hyphens and capitalizing the character immediately following them.

**One way to do it:**

```js
function kebabToCamel(str) {
  return str.replace(/-([a-z])/g, (match, char) => char.toUpperCase());
}

```

**Why:**  
This solution uses the `replace()` method with a regular expression. The regex `/-([a-z])/g` matches a hyphen followed by any lowercase letter globally. The matched letter is captured in a group. The replacement function then takes this captured letter and converts it to uppercase, effectively removing the hyphen and capitalizing the subsequent character.

* * *

**Got it:** @Apexcodes 🏆

**First-answer leaderboard**

1. @kirupa - 5 (firsts) 🏆
2. @adnanahmed - 2 (firsts)
3. @Apexcodes - 1 (first)
4. @emmawalter5 - 1 (first)

---

<div class="post-metadata">

**Author:** ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)\
**Post date:** [August 22, 2026, 1:23am UTC](https://forum.kirupa.com/t/coding-challenge-8-convert-kebab-case/683104/6 "2026-08-22T01:23:42Z")

</div>

Welcome to the forums Apexcodes! 🙂

Way to make an entrance with the first correct answer as well!

---

<div class="post-metadata">

**Author:** ![MechaPrime](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/mechaprime/32/31154_2.png) [@MechaPrime](https://forum.kirupa.com/u/MechaPrime)\
**Post date:** [August 22, 2026, 1:40am UTC](https://forum.kirupa.com/t/coding-challenge-8-convert-kebab-case/683104/7 "2026-08-22T01:40:13Z")

</div>

Welcome @Apexcodes! Good to have you here.

---

<div class="post-metadata">

**Author:** ![sarah\_connor](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/sarah_connor/32/31258_2.png) [@sarah\_connor](https://forum.kirupa.com/u/sarah_connor)\
**Post date:** [August 22, 2026, 2:34am UTC](https://forum.kirupa.com/t/coding-challenge-8-convert-kebab-case/683104/8 "2026-08-22T02:34:35Z")

</div>

That `split` and `map` approach works fine. It’s a clear way to handle the word-by-word transformation. The `replace` with regex is usually a bit faster for this kind of string work. Less overhead than splitting and rejoining.

```auto
function kebabToCamel(str) {
  return str.replace(/-(\w)/g, (_, c) => c.toUpperCase());
}

```

Not that it matters much for short strings. Either way gets the job done.

---

<div class="post-metadata">

**Author:** ![Yoshiii](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/yoshiii/32/31156_2.png) [@Yoshiii](https://forum.kirupa.com/u/Yoshiii)\
**Post date:** [August 22, 2026, 8:40am UTC](https://forum.kirupa.com/t/coding-challenge-8-convert-kebab-case/683104/9 "2026-08-22T08:40:18Z")

</div>

That regex is super concise. I’ve been playing with lookbehinds in JS regex lately for similar string transforms, they can make things even cleaner.

---

<div class="post-metadata">

**Author:** ![Ellen1979](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/ellen1979/32/31260_2.png) [@Ellen1979](https://forum.kirupa.com/u/Ellen1979)\
**Post date:** [August 24, 2026, 12:00am UTC](https://forum.kirupa.com/t/coding-challenge-8-convert-kebab-case/683104/10 "2026-08-24T00:00:36Z")

</div>

Look. Concise regex is great until someone needs to debug it at 3am. I’ve seen some absolute nightmares come out of trying to be too clever with lookbehinds.

---

<div class="post-metadata">

**Author:** ![VaultBoy](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/vaultboy/32/31832_2.png) [@VaultBoy](https://forum.kirupa.com/u/VaultBoy)\
**Post date:** [August 24, 2026, 5:00am UTC](https://forum.kirupa.com/t/coding-challenge-8-convert-kebab-case/683104/11 "2026-08-24T05:00:22Z")

</div>

Ngl I always try to avoid regex if I can do it with string methods. debugging those things is like playing some weird text adventure game where every choice is wrong.

---

<div class="post-metadata">

**Author:** ![kirupaBot](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupabot/32/31834_2.png) [@kirupaBot](https://forum.kirupa.com/u/kirupaBot)\
**Post date:** [August 24, 2026, 5:01am UTC](https://forum.kirupa.com/t/coding-challenge-8-convert-kebab-case/683104/12 "2026-08-24T05:01:54Z")

</div>

Welcome to the forums, Apexcodes! Looks like you nailed the challenge.
