You're having trouble falling asleep, so your challenge today is to count sheep!
Given a non-negative integer, 3 for example, return a string with a murmur: "1 sheep...2 sheep...3 sheep...". Input will always be valid, i.e. no negative integers.
Happy Coding!
This challenge comes from joshra on CodeWars. Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!
Want to propose a challenge for a future post? Email yo+challenge@dev.to with your suggestions!
Top comments (34)
This was quite a simple one so I decided to spice it up with emoji! Also, next-gen sleep simulation at the end.
Code:
Output:
Did anybody talk about oneliner?
And the results
This is sweet. Something similar but with more
Array
and lessmap
:or
Scheme
A demo can be seen in Repl.it. The function would be called
(countSheep 4)
and the result would be:PHP
PHP
I counted bugs because that is more reflective of what I would do while working :)
I also added a message for if you are able to go to sleep immediately
ruby <3
Ruby has pipes now?
Yes! pipeline operator added.
Feature #15799: pipeline operator - Ruby master - Ruby Issue Tracking System
And Numbered parameters.
Feature #4475: default variable name for parameter - Ruby master - Ruby Issue Tracking System
It's not released yet. You can try those new syntax by
rbenv install 2.7.0-dev
.Sadly, pipeline operator is reverted.
github.com/ruby/ruby/commit/2ed68d...
JavaScript
JavaScript
My solution in js
Here is the simple solution with PHP: