mirror of
https://github.com/Xevion/exercism.git
synced 2025-12-14 14:11:41 -06:00
add hello world properly, add rna-transcription (elixir is neat!)
This commit is contained in:
17
elixir/rna-transcription/lib/rna_transcription.ex
Normal file
17
elixir/rna-transcription/lib/rna_transcription.ex
Normal file
@@ -0,0 +1,17 @@
|
||||
defmodule RnaTranscription do
|
||||
# Turns all 1-item charlist keys and values inside the base map into integers
|
||||
@transcription %{'G' => 'C', 'C' => 'G', 'T' => 'A', 'A' => 'U'} |> Enum.map(fn ({k, v}) -> {List.first(k), List.first(v)} end) |> Enum.into(%{})
|
||||
|
||||
@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
|
||||
dna |> Enum.map(fn (x) -> Map.get(@transcription, x) end)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user