Created
May 9, 2020 18:10
-
-
Save zph/f9cd6f7538a3c80a64944eb40d7be5ee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule RnaTranscription do | |
@doc """ | |
Transcribes a character list representing DNA nucleotides to RNA | |
## Examples | |
RnaTranscription.to_rna('ACTG') | |
'UGAC' | |
""" | |
@rna_map %{?A => 'U', ?T => 'A', ?G => 'C', ?C => 'G'} | |
def lookup(k) do | |
@rna_map[k] | |
end | |
@spec to_rna([char]) :: [char] | |
def to_rna(dna) do | |
dna | |
|> Enum.map(&lookup(&1)) | |
|> Enum.reduce(&(&2 ++ &1)) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment