exercism/elixir/rna-transcription/lib/rna_transcription.ex

18 lines
411 B
Elixir

defmodule RnaTranscription do
@doc """
Transcribes a character list representing DNA nucleotides to RNA
## Examples
iex> RnaTranscription.to_rna(~c"ACTG")
~c"UGAC"
"""
@spec to_rna([char]) :: [char]
def to_rna(?G), do: ?C
def to_rna(?C), do: ?G
def to_rna(?T), do: ?A
def to_rna(?A), do: ?U
def to_rna([char | rest]), do: [to_rna(char) | to_rna(rest)]
def to_rna([]), do: []
end