exercism/elixir/flatten-array/lib/flatten_array.ex

22 lines
375 B
Elixir
Raw Normal View History

2024-07-02 16:47:44 +00:00
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