48
8
Anyone remember Boaty?
You could totally make any old word, right?
- Write a function to turn a string into Somethingy McSomethingface.
- It should accept one string as input. Ignore the case of the input.
- If the word ends in 'y', your function should not add an additional 'y' to the first instance, but should remove it in the second instance.
- If the word ends in 'ey', it should not have an additional 'y' added in the first instance, but should remove both in the second instance.
- The output should only have upper case letters in the first character, the 'M' of 'Mc' and the first character after 'Mc'.
- it only needs to work with strings of 3 or more characters.
Examples:
boat => Boaty McBoatface
Face => Facey McFaceface
DOG => Dogy McDogface
Family => Family McFamilface
Lady => Lady McLadface
Donkey => Donkey McDonkface
Player => Playery McPlayerface
yyy => Yyy McYyface
DJ Grand Master Flash => Dj grand master flashy McDj grand master flashface
What about spaces in the string, do we leave them intact? Examples:
' y'
and' '
– touch my body – 2018-03-27T17:02:19.6132I’m going to implement a suggestion from @Arnauld and make it three characters minimum. Treat whitespace just like another letter. – AJFaraday – 2018-03-27T17:04:05.600
Related: Code Johnny Code, Code! – Kevin Cruijssen – 2018-03-28T09:42:20.700
Can we assume the input will only contain upper and lowercase letters? – Kevin Cruijssen – 2018-03-28T13:16:00.483
@KevinCruijssen I haven't put any non-letters in the test cases, so they're effectively not concerned. – AJFaraday – 2018-03-28T13:17:42.143
@AJFaraday That's what I said... And regardless of what characters are in the test cases, you should clarify whether the input will contain non-letters, since a lot of commenters assume it may contain whitespace. – James – 2018-03-28T13:32:58.613
@DJMcMayhem Ahhh, good point. I've assumed whitespace is fine and that's been factored in to a lot of answers. I should have a test case for it. Probably
DJ Grand Master Flash => Dj grand master flashy McDj grand master flashface
– AJFaraday – 2018-03-28T13:34:35.800Donkey McDonkface is my favorite... seems like it would make a great insult. – NH. – 2018-03-28T16:22:55.033
This has to be the best function ever. – Three Diag – 2018-03-29T14:40:56.270
Nitpick: shouldn't that be Doggy McDogface? – craq – 2018-03-29T18:16:14.700
@craq I thought of that, but too late, unfortunately. It’s hard to change it after people have answered. – AJFaraday – 2018-03-29T18:54:03.227
Spaces in the input seem to break answers that rely on title-casing the input. – user41805 – 2018-03-30T16:16:58.910
@Cowsquack if they pass my test cases, I declare them successful. – AJFaraday – 2018-03-30T17:24:23.973