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
1.3 KiB
1.3 KiB
id, title, challengeType, dashedName
| id | title | challengeType | dashedName |
|---|---|---|---|
| 69162d64f96574d9bb629eff | Challenge 114: Camel to Snake | 29 | challenge-114 |
--description--
Given a string in camel case, return the snake case version of the string using the following rules:
- The input string will contain only letters (
A-Zanda-z) and will always start with a lowercase letter. - Every uppercase letter in the camel case string starts a new word.
- Convert all letters to lowercase.
- Separate words with an underscore (
_).
--hints--
to_snake("helloWorld") should return "hello_world".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(to_snake("helloWorld"), "hello_world")`)
}})
to_snake("myVariableName") should return "my_variable_name".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(to_snake("myVariableName"), "my_variable_name")`)
}})
to_snake("freecodecampDailyChallenges") should return "freecodecamp_daily_challenges".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(to_snake("freecodecampDailyChallenges"), "freecodecamp_daily_challenges")`)
}})
--seed--
--seed-contents--
def to_snake(camel):
return camel
--solutions--
import re
def to_snake(camel):
return re.sub(r'([A-Z])', r'_\1', camel).lower()