DEV Community

Discussion on: Help me solve the "Triple Trouble" challenge on Codewars with Elixir.

Collapse
 
antonrich profile image
Anton

I think I'm getting closer.

defmodule Triple do
  def triple_trouble(one, two, three) do
    first = String.graphemes one
    second = String.graphemes two
    third = String.graphemes three

    List.foldl(first, [], fn char1, acc1 ->
      List.foldl(second, [], fn char2, _acc2 ->
        List.foldl(third, [], fn char3, _acc3 ->
          [char1 <> char2 <> char3] ++ acc1
        end)
      end)
    end)
  end
end

Input "what", "what", "what"
Incorrect output ["ttt", "att", "htt", "wtt"]