flatten_array

This commit is contained in:
2024-07-02 12:47:44 -04:00
parent 721b4e4ed6
commit 81b389528e
10 changed files with 279 additions and 0 deletions

View 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