Last active
February 10, 2021 13:29
-
-
Save kevinkirkup/cd4566f7f18bd13fd9eee61e9ec3b756 to your computer and use it in GitHub Desktop.
Elixir HW1 - February 9, 2021
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require Integer | |
defmodule HW1 do | |
def custom_sum(a, b) when is_number(a) and is_number(b), do: {:ok, round(a) + round(b)} | |
def custom_sum(_, _), do: {:error, :badarg} | |
def even_length([]), do {:error, :must_be_even} | |
def even_length(a) when is_list(a) do | |
a_length = length(a) | |
cond do | |
Integer.is_even(a_length) -> {:ok, a_length} | |
true -> {:error, :must_be_even} | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment