Files
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

2.1 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
6821ebd4237de8297eaee791 Challenge 15: camelCase 29 challenge-15

--description--

Given a string, return its camel case version using the following rules:

  • Words in the string argument are separated by one or more characters from the following set: space ( ), dash (-), or underscore (_). Treat any sequence of these as a word break.
  • The first word should be all lowercase.
  • Each subsequent word should start with an uppercase letter, with the rest of it lowercase.
  • All spaces and separators should be removed.

--hints--

to_camel_case("hello world") should return "helloWorld".

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(to_camel_case("hello world"), "helloWorld")`)
}})

to_camel_case("HELLO WORLD") should return "helloWorld".

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(to_camel_case("HELLO WORLD"), "helloWorld")`)
}})

to_camel_case("secret agent-X") should return "secretAgentX".

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(to_camel_case("secret agent-X"), "secretAgentX")`)
}})

to_camel_case("FREE cODE cAMP") should return "freeCodeCamp".

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(to_camel_case("FREE cODE cAMP"), "freeCodeCamp")`)
}})

to_camel_case("ye old-_-sea faring_buccaneer_-_with a - peg__leg----and a_parrot_ _named- _squawk") should return "yeOldSeaFaringBuccaneerWithAPegLegAndAParrotNamedSquawk".

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(to_camel_case("ye old-_-sea  faring_buccaneer_-_with a - peg__leg----and a_parrot_ _named- _squawk"), "yeOldSeaFaringBuccaneerWithAPegLegAndAParrotNamedSquawk")`)
}})

--seed--

--seed-contents--

def to_camel_case(s):

    return s

--solutions--

import re
def to_camel_case(s):
    words = re.split(r'[_\- ]+', s)

    camel = [
        words[0].lower() if words else ''
    ] + [
        word.capitalize() for word in words[1:]
    ]

    return ''.join(camel)