DEV Community

loading...

Discussion on: Daily Challenge #40 - Counting Sheep

Collapse
thepeoplesbourgeois profile image
Josh • Edited
shep = fn n -> 1..n |> Stream.map(&("#{&1} sheep")) |> Enum.join("...") end

IO.puts(shep.(5))
# 1 sheep...2 sheep...3 sheep...4 sheep...5 sheep

⬆️elixir
That was fast... might as well do it in another language too.
⬇️javascript

const shep = (n) => new Array(n).fill(null).map((_, i) => `${i+1} sheep`).join("...")

console.log(shep(5))
// 1 sheep...2 sheep...3 sheep...4 sheep...5 sheep