The wide mouth frog is particularly interested in the eating habits of other creatures.
He just can't stop asking the creatures he encounters what they like to eat. But then he meets the alligator who just LOVES to eat wide-mouthed frogs!
When he meets the alligator, it then makes a tiny mouth.
Your goal in this kata is to create complete the mouth_size
method this method takes one argument animal
which corresponds to the animal
encountered by the frog. If this one is an alligator
(case insensitive) return small
otherwise return wide.
This challenge comes from nbeck on CodeWars. Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!
Want to propose a challenge idea for a future post? Email yo+challenge@dev.to with your suggestions!
Top comments (19)
Haskell
I see you are learning about Haskell. Congratulations! This isn't an easy language to handle (I'm am myself a learner, but aren't we all?).
I guess in your solution, cases like
"ALLIGATOR"
and"aLlIgAtOr"
won't match the first pattern and will return"wide"
. But the OP was mentioning that the"alligator"
animal was case insensitive.So I'm proposing this solution.
I took the opportunity to handle the cases where there was too much spaces (as I did in my TypeScript proposal).
This may not be the final solution, or prone to enhancement, but I guess it is a good one. We can make it better together as a community!
Am I missing something here or is this really not a challenge at all?
Challenge or not, at this time there are 6 solutions posted here, and (I believe) only 2 are completely to spec.
Most seem legit to me... Maybe a typo here and there...
and not handling case insensitivity.
F#:
But that uses an active pattern to make it case insensitive, like this;
Active Patterns provide a real nice way to move the ugly details of the case insensitive comparison out the the way.
Well, I guess in this case it's down to personal preference and style.
I think that the length of String.Equals call detracts from comprehending what the code is doing, so moving it elsewhere is achieves more than just adding a layer of indirection.
I'm also not against using match over a simple bool- I quite like the kind of tabular layout of the code.
TypeScript
JS
Swift :
Good example of why unit tests are important!
Thanks a lot for this useful input, that's a good example of why constructive criticism is important.
Sorry. You nailed it, but misspelled alligator.
In Go.
The animal isn't case insensitive in your code
mounth_size('aLlIgAtOr')
will return'wide'
while it should return'small'
Ruby:
Some comments may only be visible to logged-in visitors. Sign in to view all comments.