const nucleotides = ['A', 'C', 'G', 'T'] as const type Nucleotide = typeof nucleotides[number] type NucleotideCounts = Record function isNucleotide(char: string): char is Nucleotide { return (nucleotides as readonly string[]).includes(char) } export const nucleotideCounts = (nucleotide: string): NucleotideCounts => nucleotide.split("").map(char => (!isNucleotide(char)) ? (() => { throw new Error('Invalid nucleotide in strand')})() : char ).reduce((result, char) => ({ ...result, [char]: result[char] + 1 }), { A: 0, C: 0, G: 0, T: 0, })