Hello,
For some reason, my previous posts weren't published.
Here's my proposed solution to the challenge:
PigLatin[x_] :=
Block[{lowerVowels = {"a", "e", "i", "o", "u"}, consonants},
consonants = {"B", "C", "D", "F", "G", "H", "J", "K", "L", "M", "N",
"P", "Q", "R", "S", "T", "V", "W", "X", "Y", "Z", "b", "c", "d",
"f", "g", "h", "j", "k", "l", "m", "n", "p", "q", "r", "s", "t",
"v", "w", "x", "y", "z", "A", "E", "I", "O", "U"};
StringRiffle[
Map[If[StringFreeQ[#, lowerVowels], #,
If[StringContainsQ[StringTake[#, 1], lowerVowels],
If[Total[
Boole[StringContainsQ[Characters[#],
PunctuationCharacter]]] == 0, # <> "way",
StringJoin[Drop[Characters[#], -1]] <> "way" <>
Last[Characters[x]]],
If[Total[
Boole[StringContainsQ[Characters[#],
PunctuationCharacter]]] == 0,
StringJoin[
Reverse[TakeDrop[Characters[#],
LengthWhile[
Boole[StringContainsQ[Characters[#], consonants]], #1 ==
1 &]]]] <> "ay",
StringJoin[
Reverse[TakeDrop[Drop[Characters[#], -1],
LengthWhile[
Boole[StringContainsQ[Characters[#], consonants]], #1 ==
1 &]]]] <> "ay" <> Last[Characters[#]]]]] &,
StringSplit[x]]]]