altERnaTIng cAsE <=> ALTerNAtiNG CaSe
Define String.prototype.toAlternatingCase
(or a similar function/method such as to_alternating_case
/toAlternatingCase
/ToAlternatingCase
in your selected language; see the initial solution for details) such that each lowercase letter becomes uppercase and each uppercase letter becomes lowercase. For example:
"hello world".toAlternatingCase() === "HELLO WORLD"
"HELLO WORLD".toAlternatingCase() === "hello world"
"hello WORLD".toAlternatingCase() === "HELLO world"
"HeLLo WoRLD".toAlternatingCase() === "hEllO wOrld"
"12345".toAlternatingCase() === "12345"
"1a2b3c4d5e".toAlternatingCase() === "1A2B3C4D5E"
"String.prototype.toAlternatingCase".toAlternatingCase() === "sTRING.PROTOTYPE.TOaLTERNATINGcASE"
toAlternatingCase("hello world") === "HELLO WORLD"
toAlternatingCase("HELLO WORLD") === "hello world"
toAlternatingCase("hello WORLD") === "HELLO world"
toAlternatingCase("HeLLo WoRLD") === "hEllO wOrld"
toAlternatingCase("12345") === "12345"
toAlternatingCase("1a2b3c4d5e") === "1A2B3C4D5E"
"hello world".to_alternating_case() === "HELLO WORLD"
"HELLO WORLD".to_alternating_case() === "hello world"
"hello WORLD".to_alternating_case() === "HELLO world"
"HeLLo WoRLD".to_alternating_case() === "hEllO wOrld"
"12345".to_alternating_case() === "12345"
"1a2b3c4d5e".to_alternating_case() === "1A2B3C4D5E"
"String.prototype.toAlternatingCase".to_alternating_case() === "sTRING.PROTOTYPE.TOaLTERNATINGcASE"
"hello world".to_alternating_case() === "HELLO WORLD"
"HELLO WORLD".to_alternating_case() === "hello world"
"hello WORLD".to_alternating_case() === "HELLO world"
"HeLLo WoRLD".to_alternating_case() === "hEllO wOrld"
"12345".to_alternating_case() === "12345"
"1a2b3c4d5e".to_alternating_case() === "1A2B3C4D5E"
"String.prototype.toAlternatingCase".to_alternating_case() === "sTRING.PROTOTYPE.TOaLTERNATINGcASE"
StringUtils.toAlternativeString("hello world") == "HELLO WORLD"
StringUtils.toAlternativeString("HELLO WORLD") == "hello world"
StringUtils.toAlternativeString("hello WORLD") == "HELLO world"
StringUtils.toAlternativeString("HeLLo WoRLD") == "hEllO wOrld"
StringUtils.toAlternativeString("12345") == "12345"
StringUtils.toAlternativeString("1a2b3c4d5e") == "1A2B3C4D5E"
StringUtils.toAlternativeString("StringUtils.toAlternatingCase") == "sTRINGuTILS.TOaLTERNATINGcASE"
toAlternatingCase "hello world" `shouldBe` "HELLO WORLD"
toAlternatingCase "HELLO WORLD" `shouldBe` "hello world"
toAlternatingCase "hello WORLD" `shouldBe` "HELLO world"
toAlternatingCase "HeLLo WoRLD" `shouldBe` "hEllO wOrld"
toAlternatingCase "12345" `shouldBe` "12345"
toAlternatingCase "1a2b3c4d5e" `shouldBe` "1A2B3C4D5E"
"hello world".ToAlternatingCase() == "HELLO WORLD"
"HELLO WORLD".ToAlternatingCase() == "hello world"
"hello WORLD".ToAlternatingCase() == "HELLO world"
"HeLLo WoRLD".ToAlternatingCase() == "hEllO wOrld"
"12345".ToAlternatingCase() == "12345"
"1a2b3c4d5e".ToAlternatingCase() == "1A2B3C4D5E"
"String.ToAlternatingCase".ToAlternatingCase() == "sTRING.tOaLTERNATINGcASE"
alter_case("hello world") == "HELLO WORLD"
alter_case("HELLO WORLD") == "hello world"
alter_case("hello WORLD") == "HELLO world"
alter_case("HeLLo WoRLD") == "hEllO wOrld"
alter_case("12345") == "12345"
alter_case("1a2b3c4d5e") == "1A2B3C4D5E"
alter_case("StringUtils.toAlternatingCase") == "sTRINGuTILS.TOaLTERNATINGcASE"
to_alternating_case("hello world")
to_alternating_case("HELLO WORLD")
to_alternating_case("hello WORLD")
to_alternating_case("HeLLo WoRLD")
to_alternating_case("12345")
to_alternating_case("1a2b3c4d5e")
to_alternating_case("String.prototype.toAlternatingCase")
to_alternating_case("hello world");
to_alternating_case("HELLO WORLD");
to_alternating_case("hello WORLD");
to_alternating_case("HeLLo WoRLD");
to_alternating_case("12345");
to_alternating_case("1a2b3c4d5e");
to_alternating_case("String.prototype.toAlternatingCase");
string source = "HeLLo WoRLD";
string upperCase = to_alternating_case(source);
cout << upperCase << endl; // outputs: hEllO wOrld
toAlternatingCase("hello world") === "HELLO WORLD"
toAlternatingCase("HELLO WORLD") === "hello world"
toAlternatingCase("hello WORLD") === "HELLO world"
toAlternatingCase("HeLLo WoRLD") === "hEllO wOrld"
toAlternatingCase("12345") === "12345"
toAlternatingCase("1a2b3c4d5e") === "1A2B3C4D5E"
toAlternatingCase("String.prototype.toAlternatingCase") === "sTRING.PROTOTYPE.TOaLTERNATINGcASE"
"hello world" >alternating
"HELLO WORLD" >alternating
"hello WORLD" >alternating
"HeLLo WoRLD" >alternating
"12345" >alternating
"1a2b3c4d5e" >alternating
"String.prototype.toAlternatingCase" >alternating
ToAlternatingCase("hello world");
ToAlternatingCase("HELLO WORLD");
ToAlternatingCase("hello WORLD");
ToAlternatingCase("HeLLo WoRLD");
ToAlternativeCase("12345");
ToAlternativeCase("1a2b3c4d5e");
ToAlternativeCase("String.prototype.toAlternatingCase");
to_alternating_case "hello world"
to_alternating_case "HELLO WORLD"
to_alternating_case "hello WORLD"
to_alternating_case "HeLLo WoRLD"
to_alternating_case "12345"
to_alternating_case "1a2b3c4d5e"
to_alternating_case "String.prototype.toAlternatingCase"
As usual, your function/method should be pure, i.e. it should not mutate the original string.