flatten_array
This commit is contained in:
21
elixir/flatten-array/lib/flatten_array.ex
Normal file
21
elixir/flatten-array/lib/flatten_array.ex
Normal file
@@ -0,0 +1,21 @@
|
||||
defmodule FlattenArray do
|
||||
@doc """
|
||||
Accept a list and return the list flattened without nil values.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> FlattenArray.flatten([1, [2], 3, nil])
|
||||
[1, 2, 3]
|
||||
|
||||
iex> FlattenArray.flatten([nil, nil])
|
||||
[]
|
||||
|
||||
"""
|
||||
|
||||
@spec flatten(list) :: list
|
||||
def flatten(list) do
|
||||
list
|
||||
|> List.flatten()
|
||||
|> Enum.reject(&is_nil/1)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user