Last active
October 24, 2018 10:18
-
-
Save boddhisattva/bb5b584605c6b6f1870862c73e754cb9 to your computer and use it in GitHub Desktop.
RNA Transcription Exercise - Elixir
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 | |
@guanine "G" | |
@adenine "A" | |
@cystosine "C" | |
@uracil "U" | |
@thymine "T" | |
@doc """ | |
Transcribes a character list representing DNA nucleotides to RNA | |
## Examples | |
iex> RNATranscription.to_rna('ACTG') | |
'UGAC' | |
""" | |
@spec to_rna([char]) :: [char] | |
def to_rna(dna) do | |
rna_strand = | |
Enum.map(String.graphemes(to_string(dna)), fn dna_char -> | |
case dna_char do | |
@guanine -> @cystosine | |
@cystosine -> @guanine | |
@thymine -> @adenine | |
@adenine -> @uracil | |
_ -> "Error" | |
end | |
end) | |
rna_strand | |
|> to_string | |
|> to_charlist | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment