Nucleotide Count
This commit is contained in:
@@ -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,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user