DEV Community

Discussion on: Daily Challenge #46 - ???

Collapse
 
thepeoplesbourgeois profile image
Josh • Edited

... 😐

I mean... that's not even a function to write. It's a function to call.

Elixir:

"What is this? What's happening??" |> String.replace("?", "")

Ruby:

"What is this? What's happening??".gsub("?", "")

JavaScript:

"What is this? What's happening??".replace(/\?/g, "")

Bash:

echo "What is this? What's happening??" | sed s/\?//g
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"