Oh, No!
the sentences are out of balance.
Quick! balance them.
A word is defined as follows:
A sequence of letters [A-Za-z] separated by any non-letter character ([0-9] ~+- etc.)
A word is BaLanCeD if its capitalization is the same forwards as it is backwards.
Given a sentence with words, balance each word by capitalizing a letter on the right-hand side for each uppercase letter on the left-hand side, and the other way around. Do not make uppercase letters lowercase.
Rules
- For each letter
n
chars from the beginning of a word, it and the lettern
chars from the end of the word should both be made uppercase if either of them is upper case. - All input will be printable ASCII (codepoints 32
~
).
No need to balance if:
- The capital is in the middle of a term (word) (equal amount of letters on each side)
- No capitals are present in the term
Example:
eeeeE → EeeeE
eEeee → eEeEe
eeEee → eeEee
Eeee. → EeeE.
{EEee}1EEeEEEeeeeee → {EEEE}1EEeEEEEEEeEE
TesT CaSeS:
It was the first new century. →
IT was the first new century.
IiIIiiIIiiiI Ii iI iiiI iiii iIi. →
IiIIIIIIIIiI II II IiiI iiii iIi.
I sueD the airport for misplacing my Luggage. – I lost my Case. →
I SueD the airport for misplacing my LuggagE. – I lost my CasE.
The Policemen CraCked THE CaSE of the lost cocaIne. →
ThE PolicemeN CraCkeD THE CASE of the lost coCaIne.
JUST IN CASE. →
JUST IN CASE.
If(!1){ /\hElloBinOLIngo}elsE{ print( 'bOn aPPetit')} →
IF(!1){ /\hElLOBinOLInGo}ElsE{ print( 'bOn aPPeTIt')}
xK/TH"E7k['VyO%t>2`&{B9X.8^$GWc=!+@ 3Us}]JFM)jbuI,-:alPw*Qvpq5zi\Z(_n1dC~?<;fDAm0SR|eYg6#rN4Lho →
XK/TH"E7k['VyO%t>2`&{B9X.8^$GWC=!+@ 3US}]JFM)JbuI,-:aLPw*QvpQ5zi\Z(_n1DC~?<;fDAm0SR|eYg6#RN4LhO
Foo_bar →
FoO_bar
(the " →" will not be included in the input)
This is codegolf, so attempt to achieve least amount of bytes
Foo_bar
. To make sure that words are not matched with\w+
. \$\endgroup\$