In that Coding Golf, you should convert one coding convention with TitleCase to lower_case_with_underscores. And... vice versa!
#Specification
Specification
Change the casing in a following way:
- If underscore character is a delimiter, change the casing to Title Case without any of delimiter.
- If there are multiple words with no delimiter, change the casing to lower case and add an underscore character as a delimiter.
- In case of only one word (or one character): change the casing to Title Case if the word starts with lower case; change the casing to lower case if the word starts with the upper case.
Allowed characters:
- A to Z
- a to z
- underscore (
_
).
Input with mixed cased words are disallowed. Examples of disallowed cases:
Coding_Convention_Conversion
a_BC
#Example Cases
Example Cases
Input | Expected Output
===========================================================
CodingConventionConversion | coding_convention_conversion
coding_convention_conversion | CodingConventionConversion
abc | Abc
Abc | abc
ABC | a_b_c
a_b_c | ABC
a | A
A | a
Rules
- It is allowed to use
ToUpper
,ToLower
andToTitleCase
functions. - Using regular expressions is allowed.
- code-golf: shortest code in bytes wins!