25 lines
535 B
TypeScript
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("");
|