Implement a simple version of flatten
This commit is contained in:
parent
1be7896f19
commit
a52453ed54
|
@ -45,6 +45,23 @@ defmodule MyEnum do
|
|||
end
|
||||
end
|
||||
|
||||
# I gave up on these two.
|
||||
# split
|
||||
# take
|
||||
end
|
||||
|
||||
defmodule MyList do
|
||||
def flatten([]) do
|
||||
[]
|
||||
end
|
||||
|
||||
def flatten([head|tail]) do
|
||||
# this is basically the recursion
|
||||
flatten(head) ++ flatten(tail)
|
||||
end
|
||||
|
||||
def flatten(head) do
|
||||
# if there's only on element, we make a list out of it, so that we can concat them
|
||||
[head]
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue