Created
June 15, 2016 08:05
-
-
Save JoshCheek/460d79388a72f15bf96e4d6df1b007d6 to your computer and use it in GitHub Desktop.
Playing with elixir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule MyList do | |
def flatten([]), do: [] | |
def flatten([head|tail]), do: concat (flatten head), (flatten tail) | |
def flatten(other), do: [other] | |
def concat([], list), do: list | |
def concat([head|tail], list), do: [head|(concat tail, list)] | |
def reverse(list), do: reverse list, [] | |
def reverse([], reversed), do: reversed | |
def reverse([head|tail], reversed), do: reverse tail, [head|reversed] | |
end | |
IO.inspect MyList.reverse MyList.flatten [1,[2,3,[[[4],5],6],7,[8]],9] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment