Last active
August 1, 2017 17:52
-
-
Save ronualdo/370c9c258cc0c1131fa5ced6b7282878 to your computer and use it in GitHub Desktop.
A small exercise in elixir. Just a function to flatten an array. Tests for this function can be found in https://gist.github.com/ronualdo/66e2339a17a7c33229ca61bda977765e
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 Flatten do | |
def flat(list=[]) do | |
list | |
end | |
def flat([head|tail]) when is_list(head) do | |
flat(head) ++ flat(tail) | |
end | |
def flat([head|tail]) do | |
[head] ++ flat(tail) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment