re: Daily Challenge #81 - Even or Odd VIEW POST

FULL DISCUSSION
 

Elixir:

defmodule Day81 do
  require Integer

  @spec even_or_odd(String.t()) :: String.t()
  def even_or_odd(string) do
    {even, odd} =
      string
      |> String.graphemes()
      |> Enum.map(&String.to_integer/1)
      |> Enum.split_with(&Integer.is_even/1)

    {even, odd} = {Enum.sum(even), Enum.sum(odd)}

    cond do
      even > odd -> "Even is greater than Odd"
      odd > even -> "Odd is greater than Even"
      true -> "Even and Odd are the same"
    end
  end
end
 

I read graphmemes instead of graphemes, I should probably stop browsing the internet for today...

 
code of conduct - report abuse