Given a DNA strand, return its RNA complement (per RNA transcription).
Both DNA and RNA strands are a sequence of nucleotides.
The four nucleotides found in DNA are adenine (A), cytosine (C), guanine (G) and thymine (T).
The four nucleotides found in RNA are adenine (A), cytosine (C), guanine (G) and uracil (U).
Given a DNA strand, its transcribed RNA strand is formed by replacing each nucleotide with its complement:
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
(ns rna-transcription-test (:require [clojure.test :refer [deftest is]] rna-transcription)) (deftest transcribes-cytosine-to-guanine (is (= "G" (rna-transcription/to-rna "C")))) (deftest transcribes-guanine-to-cytosine (is (= "C" (rna-transcription/to-rna "G")))) (deftest transcribes-adenine-to-uracil (is (= "U" (rna-transcription/to-rna "A")))) (deftest it-transcribes-thymine-to-adenine (is (= "A" (rna-transcription/to-rna "T")))) (deftest it-transcribes-all-nucleotides (is (= "UGCACCAGAAUU" (rna-transcription/to-rna "ACGTGGTCTTAA")))) (deftest it-validates-dna-strands (is (thrown? AssertionError (rna-transcription/to-rna "XCGFGGTDTTAA"))))
(ns rna-transcription) (defn to-rna-single [dna] (cond (= dna \G) \C (= dna \C) \G (= dna \T) \A (= dna \A) \U :else (throw (AssertionError. "Invalid nucleotide")))) (defn to-rna [dna] (apply str (map to-rna-single dna)))
A huge amount can be learned from reading other people’s code. This is why we wanted to give exercism users the option of making their solutions public.
Here are some questions to help you reflect on this solution and learn the most from it.