22 lines
375 B
Elixir
22 lines
375 B
Elixir
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
|