Write a function MyList.span(from,to) that returns a list of the numbers from up to to.
Not sure if I completed this exercise correctly. I approached it using the recursive pattern matching as described in the previous example. But my solution feels strange. Elixir is new to me so I am reaching out to y’all
defmodule MyList do def span(from, to) do _span [to], from end defp _span(list = [ from | _tail ], from), do: list defp _span([ head | tail ], from) do _span([head - 1] ++ [head | tail], from) end end
Is there a better way to approach this that the original authors had in mind? What feels weird to me is the concatenation…