DEV Community

loading...

Discussion on: Daily Challenge #34 - WeIrD StRiNg CaSe

Collapse
brightone profile image
Oleksii Filonenko

Elixir:

defmodule Case do
  require Integer

  def weird(string) do
    string
    |> String.graphemes()
    |> Enum.with_index()
    |> Enum.map(fn
      {char, i} when Integer.is_even(i) -> String.upcase(char)
      {char, _} -> String.downcase(char)
    end)
    |> Enum.join()
  end
end