Nucleotide Count

This commit is contained in:
2025-04-18 17:33:55 +02:00
parent 83ec49cb5b
commit 1757bdbd76
6 changed files with 25476 additions and 7 deletions

View File

@@ -1,3 +1,21 @@
export function nucleotideCounts(/* Parameters go here */) {
throw new Error('Remove this statement and implement this function')
const nucleotides = ['A', 'C', 'G', 'T'] as const
type Nucleotide = typeof nucleotides[number]
type NucleotideCounts = Record<Nucleotide, number>
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,
})