Skip to main content
4 of 5
added 15 characters in body
Dariusz Woźniak
  • 1.3k
  • 1
  • 12
  • 16

Coding Convention Conversion

In that Coding Golf, you should convert one coding convention with TitleCase to lower_case_with_underscores. And... vice versa!

#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

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 and ToTitleCase functions.
  • Using regular expressions is allowed.
  • : shortest code in bytes wins!
Dariusz Woźniak
  • 1.3k
  • 1
  • 12
  • 16