DNA to RNA Conversion

Lee·2022년 6월 20일

Algorithm

목록 보기
22/92
post-thumbnail

❓ Complementary DNA

Q. 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').

Create a function which translates a given DNA string into RNA.

For example:

"GCAT" => "GCAU"
The input string can be of arbitrary length - in particular, it may be empty. All input is guaranteed to be valid, i.e. each input string will only ever consist of 'G', 'C', 'A' and/or 'T'.

Examples (Input ==> Output):
"Robin Singh" ==> ["Robin", "Singh"]

"I love arrays they are my favorite" ==> ["I", "love", "arrays", "they", "are", "my", "favorite"]

✔ Solution

function DNAtoRNA(dna) {
  // create a function which returns an RNA sequence from the given DNA sequence
  let dnaArr = dna.split("");
  for (let i = 0; i < dnaArr.length; i++) {
    if (dnaArr[i] === "T") dnaArr[i] = "U";
  }
  let lastValue = dnaArr.join("");
  return lastValue;
}
profile
Lee

0개의 댓글