Skip to content

Instantly share code, notes, and snippets.

@kevinkirkup
Last active February 10, 2021 13:29
Show Gist options
  • Save kevinkirkup/cd4566f7f18bd13fd9eee61e9ec3b756 to your computer and use it in GitHub Desktop.
Save kevinkirkup/cd4566f7f18bd13fd9eee61e9ec3b756 to your computer and use it in GitHub Desktop.
Elixir HW1 - February 9, 2021
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