Javascript: DNA to RNA

JS: Objects
Last update: 14 Sep 16:10
0
Students

DNA and RNA are nucleotide sequences.

The four nucleotides in DNA are adenine (A), cytosine (C), guanine (G), and thymine (T).

The four nucleotides in RNA are adenine (A), cytosine (C), guanine (G), and uracil (U).

The RNA strand is made up of the DNA strand by sequentially replacing each nucleotide:

  • G -> C
  • C -> G
  • T -> A
  • A -> U

dnaToRna.js

Implement and export as default a function that takes a DNA strand and returns the corresponding RNA strand (performs RNA transcription).

If the input parameter does not contain a single nucleotide (i.e. an empty string is passed in), the function should return an empty string. If an "unknown" nucleotide (not one of the four listed above) is found, the function must return null.

dnaToRna('ACGTGGTCTTAA'); // 'UGCACCAGAAUU'
dnaToRna('CCGTA'); // 'GGCAU'
dnaToRna(''); // ''
dnaToRna('ACNTG'); // null

For full access to the challenge you need a professional subscription.

A professional subscription will give you full access to all Hexlet courses, projects and lifetime access to the theory of lessons learned. You can cancel your subscription at any time.

Get access
130
courses
1000
exercises
2000+
hours of theory
3200
tests