-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdnaToRna.js
27 lines (20 loc) · 991 Bytes
/
dnaToRna.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
/*
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'.
*/
function DNAtoRNA(dna) {
// create a function which returns an RNA sequence from the given DNA sequence
let RNA = '';
for (let i = 0; i < dna.length; i++) {
if (dna.charAt(i) != 'T') {
RNA += dna.charAt(i);
} else {
RNA += 'U';
}
}
return RNA;
}