Welcome to the bar!
We recommend you drink 1 glass of water per drink so you're not hungover tomorrow morning. Your fellow coders have bought you several drinks tonight in the form of strings. Return a string suggesting how many glasses of water you should drink to not be hungover.
If you would like to keep things simple, you can consider any "numbered thing" in the string to be a drink. Even "1 bear" => "1 glass of water" or "1 chainsaw and 2 pools" => "3 glasses of water".
Example Pairs
Input 0:
"1 beer"
Output 0:
"1 glass of water"
Input 1:
"1 shot, 5 beers, 2 shots, 1 glass of wine, 1 beer"
Output 1:
"10 glasses of water"
Tests
hydrate("1 beer")
hydrate("2 glasses of wine and 1 shot")
hydrate("1 shot, 5 beers, 2 shots, 1 glass of wine, 1 beer")
Good luck!
This challenge comes from taylormb 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 (18)
Python solution
I want to suggest a challenge. What should be the subject of my email? Can I send a markdown file?
Hey Vidit, I'm happy to hear you wanna suggest a challenge. You can send any suggestions to yo+challenge@dev.to. Feel free to drop the content of your challenge in the email, markdown file works too. Subject doesn't matter too much, we'll know what it is.
Take care!
Thanks!
Using regular expressions in JavaScript:
We get the following results:
I didn't see yours, but mine is practically identical 😮
Yours has some checks that make it more robust... And that I probably should add to mine 😳
My solution in python
Js vanilla solution (fix below)

What if I drink "11 beers"?
(I have a feeling I'll be severely under-hydrated)
Oh, that's interesting. I'll upload a fix asap. Thanks for reporting!
EDIT: fixed! The problem was the split -not necessary. Also have forgot the existence of reduce! I need a vacation
Your theme looks amazing, what is it?
Thank you! It's a customization I've made from Material Ocean, nothing special :)
Any chance you would be willing to upload it for me somewhere? :)
Well, I could send it to you by email but note that I had customize only the Js, Sass, Css. HTML and Ts parts. Let me know!
Python solution 🐍
My swift solution :