Files
exercise-typescript/typescript/rna-transcription/rna-transcription.ts
2022-11-02 21:47:48 +01:00

25 lines
535 B
TypeScript

const COMPLEMENTS = {
G: "C",
C: "G",
T: "A",
A: "U",
} as const;
type NUCLEOTIDE = keyof typeof COMPLEMENTS;
const nucleotides = Object.keys(COMPLEMENTS);
const isNucleotide = (nucleotide: string): nucleotide is NUCLEOTIDE =>
nucleotides.includes(nucleotide);
export const toRna = (dnaStrand: string): string =>
dnaStrand
.split("")
.map((nucleotide) => {
if (!isNucleotide(nucleotide)) {
throw new Error("Invalid input DNA.");
}
return COMPLEMENTS[nucleotide];
})
.join("");