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!
Latest comments (34)
Here is the simple solution with PHP:
Python
My solution in js
[gist.github.com/devparkk/334ee3d1f...]
Erlang:
Python :
In one line :
Rust solution: [Playground](
β¬οΈelixir
That was fast... might as well do it in another language too.
β¬οΈjavascript
ruby <3
Ruby has pipes now?
Sadly, pipeline operator is reverted.
github.com/ruby/ruby/commit/2ed68d...
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
.Scheme
A demo can be seen in Repl.it. The function would be called
(countSheep 4)
and the result would be: