As an Elixir function, including documentation! And a language feature I'm writing about in an upcoming post UPDATE: the post is up!! 😃
defmoduleWdo@doc~S"""
Takes in a string, ensures it's downcased, converts it to a charlist,
and then processes the charlist by subtracting the proper amount from
the `next` raw byte to arrive at the same capitalized character in the
ASCII chart. This letter is then inserted into an iodata list in
between the raw bytes that have already been `waved` through and the
`rest` of the raw bytes. This iodata list is then converted back to a
string, which is added to the head of a list of strings that represent
the in-motion version of the wave. To finalize the in-motion wave, it
is reversed once the input charlist has been fully processed.
When `next` is not a lowercase letter, it is added to `waved` without
adding a new string to `waves`.
## Examples
iex>W.ave("HELLO")
["Hello", "hEllo", "heLlo", "helLo", "hellO"]
iex>W.ave("helloworld!")
["Helloworld!", "hElloworld!", "heLloworld!", "helLoworld!", "hellOworld!",
"helloWorld!", "hellowOrld!", "hellowoRld!", "helloworLd!", "helloworlD!"]
"""defave(string)dostring|>String.downcase|>String.to_charlist|>do_waveend@ascii_upcase_val32# ?a - ?Adefpdo_wave(waving,waves\\[],waved\\'')defpdo_wave([]=_done_waving,waves,_waved),do:Enum.reverse(waves)defpdo_wave([next|rest],waves,waved)whennextin?a..?zdouppercase=next-@ascii_upcase_valdo_wave(rest,[IO.iodata_to_binary([waved,uppercase,rest])|waves],[waved,next])enddefpdo_wave([next|rest],waves,waved),do:do_wave(rest,waves,[waved,next])end
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
As an Elixir function, including documentation! And a language feature I'm writing about in
an upcoming postUPDATE: the post is up!! 😃