Exercism JS: RNA Transcription

Write a program that, given a DNA strand, returns 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:

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

My solution:

screen-shot-2016-12-14-at-11-14-35-pm

Another solution that introduces more advanced concepts like the ‘this’ object constructor and returning a function within a function.

screen-shot-2016-12-14-at-11-03-13-pm

Things to note:

  • ‘this’ allows you to access an object when you’re creating the new object later using the module.  (ie. var dnaTranscriber = new DnaTranscriber();)
  • splitting a string converts it into an array
  • .map allows you to apply the same method to every item in an array.

Javascript is so much harder to grasp than Ruby. 😐

Advertisements
Exercism JS: RNA Transcription

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s