I am working through example questions from Programming Elixir (PragProg). The question is to write a function that returns numbers from
to to
. My solution is as below. However, sometimes they return characters (equivalent to their ascii). How can I avoid that and return numbers only.
defmodule MyList do
def span(), do: []
def span(from), do: [from]
def span(from, to) when from == to, do: [from]
def span(from, to) when from > to, do: [from] ++ span(from - 1, to)
def span(from, to) when from < to, do: [from] ++ span(from + 1, to)
end
MyList.span(31,34) #=> [31,32,33,34]
MyList.span(-5,-8) #=> [-5,-6,-7,-8]
MyList.span(65,68) #=> 'ABCD' (I need a list with numbers 65 to 68)