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
+16691
View File
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large Load Diff
Binary file not shown.
@@ -1,4 +1,4 @@
import { describe, it, expect, xit } from '@jest/globals'
import { describe, expect, it } from '@jest/globals'
import { nucleotideCounts } from './nucleotide-count.ts'
describe('count all nucleotides in a strand', () => {
@@ -12,7 +12,7 @@ describe('count all nucleotides in a strand', () => {
expect(nucleotideCounts('')).toEqual(expected)
})
xit('can count one nucleotide in single-character input', () => {
it('can count one nucleotide in single-character input', () => {
const expected = {
A: 0,
C: 0,
@@ -22,7 +22,7 @@ describe('count all nucleotides in a strand', () => {
expect(nucleotideCounts('G')).toEqual(expected)
})
xit('strand with repeated nucleotide', () => {
it('strand with repeated nucleotide', () => {
const expected = {
A: 0,
C: 0,
@@ -32,7 +32,7 @@ describe('count all nucleotides in a strand', () => {
expect(nucleotideCounts('GGGGGGG')).toEqual(expected)
})
xit('strand with multiple nucleotides', () => {
it('strand with multiple nucleotides', () => {
const expected = {
A: 20,
C: 12,
@@ -46,7 +46,7 @@ describe('count all nucleotides in a strand', () => {
).toEqual(expected)
})
xit('strand with invalid nucleotides', () => {
it('strand with invalid nucleotides', () => {
const expected = 'Invalid nucleotide in strand'
expect(() => {
nucleotideCounts('AGXXACT')
@@ -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,
})
File diff suppressed because it is too large Load Diff