logo

DNA to RNA Conversion

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.


My code:

function DNAtoRNA(dna) {
                        let dnaArr = dna.toUpperCase().split('');
                        let rna = [];
                        for (let i = 0; i < dnaArr.length; i++) {
                          if (dnaArr[i] === 'T') {
                            rna.push('U');
                          } else {
                            rna.push(dnaArr[i]);
                          }
                        }
                        return rna.join('');
                      }                                                          
                    


And that's the best solution among all users:

function DNAtoRNA(dna){
                        return dna.replace(/T/g, 'U');
                      }
                    

New things I learned today: