Created
March 4, 2023 23:34
-
-
Save Git-I985/4b89a0a3aae12f685b304a3f61119efa to your computer and use it in GitHub Desktop.
DNA to RNA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @ts-check | |
/* eslint no-restricted-syntax: ["off", "ForOfStatement"] */ | |
// BEGIN (write your solution here) | |
const map = { | |
G: "C", | |
C: "G", | |
T: "A", | |
A: "U", | |
} | |
export default (dna) => { | |
const dnaNucleotids = dna.split('') | |
let result = '' | |
for (const dnaNucleotid of dnaNucleotids) { | |
const rnaNucleotid = map[dnaNucleotid] | |
if(!rnaNucleotid) { | |
result = null | |
break | |
} else { | |
result += rnaNucleotid | |
} | |
} | |
return result | |
} | |
// OR | |
export default (dna) => { | |
const dnaNucleotids = dna.split('') | |
const known = (dnaNucleotid) => Object.hasOwn(map, dnaNucleotid) | |
const dnaToRnaMapper = (dnaNucleotid) => map[dnaNucleotid] | |
return dnaNucleotids.every(known) ? dnaNucleotids.map(dnaToRnaMapper).join('') : null | |
} | |
// END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment