DEV Community

Discussion on: Daily Challenge #46 - ???

Collapse
 
thepeoplesbourgeois profile image
Josh

Okay, I'll bite and imagine that Carmen Sandiego has stolen all the regular expressions!

defmodule DarnYouCarmen do
  # Quick, destroy the question marks before she steals them, too!
  def whats_a_question(string, processed \\ [])
  def whats_a_question("", processed), do: IO.chardata_to_binary(processed)
  def whats_a_question("?"<>string, processed), do: whats_a_question(string, processed)
  def whats_a_question(<<next :: utf8>> <> string, processed), do: whats_a_question(string, [processed, next]
end

DarnYouCarmen.whats_a_question("What is this? What's happening??")
# "What is this What's happening"