Created
July 5, 2019 13:12
-
-
Save KamilLelonek/01d79bc4f42dfab2ab1eaea8ccbc99de to your computer and use it in GitHub Desktop.
This file contains hidden or 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 List do | |
def flatten(list, acc \\ []) | |
def flatten([], acc), do: acc | |
def flatten([[] | t], acc), do: flatten(t, acc) | |
def flatten([h | t], acc) when is_list(h), do: flatten(h, flatten(t, acc)) | |
def flatten([h | t], acc), do: [h | flatten(t, acc)] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment