Last active
June 24, 2018 20:19
-
-
Save daniel-nelson/f159794685fc860986752a1d3390fc6a to your computer and use it in GitHub Desktop.
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
# | |
# my solution to ListsAndRecursion-6 of Programming Elixir 1.6 | |
# | |
defmodule MyList do | |
def flatten([]) do | |
[] | |
end | |
def flatten([head | tail]) when is_list(head) do | |
flatten(head) ++ flatten(tail) | |
end | |
def flatten([head | tail]) do | |
[head | flatten(tail)] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment