Ninjas frequently need to signal each other in code. They often employ natural sounds as cover. Our ninja will chirp like a bird, with different amounts of chirps signifying different messages.
chirp(4); //output would be chirp-chirp-chirp-chirp.
Consider String.prototype.repeat
,String.prototype.padStart
, and String.prototype.padEnd
disabled for this challenge, you'll have to think recursively to avoid detection.
Good luck!
This challenge comes from nodesolomon 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 (15)
Javascript
Hot
Small solution in Python 3.X 😄
Nice one! But you forgot an edge case. I can still call it with a negative value and get a recursion error.
I think you should add another
if else
branch for when the value is less or equal than zero.Given some context, which is ninjas talking, I doubt that they can talk negativly or that not talking at all is considered as talking
However, without those information, I fully agree ! 😄
I was reading the old ninja scroll all wrong... Thanks sensei 😁
My first submission at Dev.To! (Excluding the welcome post). I love computer science.
Java
Note that this assumes a few things:
None recursive javascript solution
`
As always, there is no need to use any language but Elixir. We'll establish a signature with a guard clause to make sure the user can only pass a natural number, and a private
chirp_
signature to do the work of building the list of chirps, with a default empty list as its second argument. We could useList.duplicate
, if the point of this exercise wasn't to make a recursive call 😜JavaScript
Decided to throw an error if the count is not greater than zero because a ninja won't bother spending energy on calling this secret technique for no purposes.
Training dojo available here (say
chirp
to enter).Reason
Elm
Haskell:
Also, you never said anything about Haskell standard functions :)
My solution in js