-
Notifications
You must be signed in to change notification settings - Fork 0
/
DNA to RNA.js
28 lines (22 loc) · 893 Bytes
/
DNA to RNA.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*
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'.
*/
const DNAtoRNA=(dna)=>{
let rna = ''
for (let i = 0; i < dna.length; i++) {
if (dna[i]==='T') {
rna +='U'
}
else {rna +=dna[i]}
}
return rna
}
console.log(DNAtoRNA("GCAT"));