DNA to RNA conversion using JavaScript

JavascriptWeb DevelopmentFront End Technology

DNA And RNA Relation

Deoxyribonucleic acid, DNA is the primary information storage molecule in biological systems. It is composed of four nucleic acid bases Guanine ('G'), Cytosine ('C'), Adenine ('A'), and Thymine ('T').

Ribonucleic acid, RNA, is the primary messenger molecule in cells. RNA differs slightly from DNA its chemical structure and contains no Thymine. In RNA Thymine is replaced by another nucleic acid Uracil ('U').

Problem

We are required to write a JavaScript function which translates a given DNA string into RNA.

Example

Following is the code −

 Live Demo

const DNA = 'GCAT';
const DNAtoRNA = (DNA) => {
   let res = '';
   for(let i = 0; i < DNA.length; i++){
      if(DNA[i] === "T"){
         res += "U";
      }else{
         res += DNA[i];
      };
   };
   return res;
};
console.log(DNAtoRNA(DNA));

Output

GCAU
raja
Published on 17-Apr-2021 13:25:13
Advertisements