Inspired by this.
Given a string as input consisting of only upper and lowercase alphabet characters, wicka-wub it.
How do I wicka-wub a string?
The example text used is "DJMcMayhem".
Split the string before each capital letter, so you get ["D", "J", "Mc", "Mayhem"]
.
Next, take the two halves of the list as sublists. This gives us [["D", "J"],["Mc", "Mayhem"]]
. If the list is an odd length (i.e. 3), the first sublist will contain the middle substring (i.e. [[a,b], [c]]
).
Create a list of wicka
s and wub
s. The number of wicka
s should be as many as the length of the first part of the input list (i.e. ["D", "J"] -> ["wicka", "wicka"]
), and the number of wubs
should be as many as the length of the second part of the input list. In our case, this gives ["wicka", "wicka", "wub", "wub"]
.
Now join the sublists of the input list into single strings and flatten.
We currently have ["DJ", "McMayhem"]
and ["wicka", "wicka", "wub", "wub"]
.
Join the wicka
/wub
list with -
s: wicka-wicka-wub-wub
. Prepend a -
. If there is more than one capital letter in the input, append another -
.
Now we have ["DJ", "McMayhem"]
and "-wicka-wicka-wub-wub-"
.
Append the wicka-wub
string to the end of the first item in the input list, to get ["DJ-wicka-wicka-wub-wub-","McMayhem"]
.
Lastly, repeat the characters in the second part of the string by their 0-indexed value in the original input string. In our example, that means the first M
would be repeated twice, then the c
three times, and the next M
four times. Join the list, so the second part (the part you just repeated letters in) is appended to the first part ("DJ-wicka-wicka-wub-wub-"
).
Final result of input:
"DJ-wicka-wicka-wub-wub-MMcccMMMMaaaaayyyyyyhhhhhhheeeeeeeemmmmmmmmm"
Total process:
["D", "J", "Mc", "Mayhem"] =>
[["D", "J"], ["Mc", "Mayhem"]] =>
["DJ", "McMayhem"] and ["wicka", "wicka", "wub", "wub"] =>
["DJ", "McMayhem"] and "-wicka-wicka-wub-wub-" =>
["DJ-wicka-wicka-wub-wub-", "McMayhem"] =>
"DJ-wicka-wicka-wub-wub-MMcccMMMMaaaaayyyyyyhhhhhhheeeeeeeemmmmmmmmm"
Your task
Your task is, given a string that consists of only upper and lowercase alphabet characters, output the wicka-wubbed version of that string.
A few rules
- The input may consist entirely of lowercase letters, or entirely of uppercase letters, or any number of each, but no other characters.
- If the input consists of entirely lowercase letters the correct output should simply be the final stage (the string with the characters repeated according to their 0-indexed position). There should be no
wicka
orwub
in that case. - Standard rules apply, full programs or functions, up to you.
- This is a code-golf so shortest code wins.
GoodLuck-wicka-wicka-wub-GGGGGGGGooooooooollllllllllfffffffffffeeeeeeeeeeerrrrrrrrrrrrrssssssssssssss
Test cases
input => output
DJMcMayhem => DJ-wicka-wicka-wub-wub-MMcccMMMMaaaaayyyyyyhhhhhhheeeeeeeemmmmmmmmm
PPCG => PP-wicka-wicka-wub-wub-CCGGG
foobarbaz => fooooobbbbaaaaarrrrrrbbbbbbbaaaaaaaazzzzzzzzz
FooBarBaz => FooBar-wicka-wicka-wub-BBBBBBaaaaaaazzzzzzzz
HelloWorld => Hello-wicka-wub-WWWWWoooooorrrrrrrllllllllddddddddd
Test => Test-wicka
UPPER => UPP-wicka-wicka-wicka-wub-wub-EEERRRR
fooBarBaz => fooBar-wicka-wicka-wub-BBBBBBaaaaaaazzzzzzzz
5
uppercase letters? \$\endgroup\$foobarbaz
simply returnfoobarbaz
? Is there a second part at all? \$\endgroup\$