Sha256: f418c059bfe9a95686e5dfb38a6868e7c2b787fcd03689be3d69b6a2d1eb8da0

Contents?: true

Size: 1.92 KB

Versions: 68

Compression:

Stored size: 1.92 KB

Contents

class ProteinTranslation {
    static translations = [
        {codon: 'AUG', protein: 'Methionine'},
        {codon: 'UUU', protein: 'Phenylalanine'},
        {codon: 'UUC', protein: 'Phenylalanine'},
        {codon: 'UUA', protein: 'Leucine'},
        {codon: 'UUG', protein: 'Leucine'},
        {codon: 'UCU', protein: 'Serine'},
        {codon: 'UCC', protein: 'Serine'},
        {codon: 'UCA', protein: 'Serine'},
        {codon: 'UCG', protein: 'Serine'},
        {codon: 'UAU', protein: 'Tyrosine'},
        {codon: 'UAC', protein: 'Tyrosine'},
        {codon: 'UGU', protein: 'Cysteine'},
        {codon: 'UGC', protein: 'Cysteine'},
        {codon: 'UGG', protein: 'Tryptophan'},
        {codon: 'UAA', protein: 'STOP'},
        {codon: 'UAG', protein: 'STOP'},
        {codon: 'UGA', protein: 'STOP'}
    ]

    static proteins(strand: string) {
        const codons = this.breakStrandIntoCodons(strand)
        return this.getProteinsFromCodons(codons)
    }

    private static breakStrandIntoCodons(strand: string): string[] {
        const result: string[] = []
        for (let i = 0; i <= strand.length - 1; i++) {
            result.push(strand.slice(0, 3))
            strand = strand.slice(3)
        }
        return result
    }

    private static getProteinsFromCodons(codons: string[]) {
        const result: string[] = []
        for (const codon of codons) {
            const protein = this.getProteinFromCodon(codon)
            if (protein !== 'STOP') {
                result.push(protein)
            } else {
                break
            }
        }
        return result
    }

    private static getProteinFromCodon(codon: string): string {
        let result = ''
        for (const translation of this.translations) {
            if (translation.codon === codon) {
                result = translation.protein
                break
            }
        }
        return result
    }
}

export default ProteinTranslation

Version data entries

68 entries across 68 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/typescript/exercises/protein-translation/protein-translation.example.ts
trackler-2.2.1.179 tracks/typescript/exercises/protein-translation/protein-translation.example.ts
trackler-2.2.1.178 tracks/typescript/exercises/protein-translation/protein-translation.example.ts
trackler-2.2.1.177 tracks/typescript/exercises/protein-translation/protein-translation.example.ts
trackler-2.2.1.176 tracks/typescript/exercises/protein-translation/protein-translation.example.ts
trackler-2.2.1.175 tracks/typescript/exercises/protein-translation/protein-translation.example.ts
trackler-2.2.1.174 tracks/typescript/exercises/protein-translation/protein-translation.example.ts
trackler-2.2.1.173 tracks/typescript/exercises/protein-translation/protein-translation.example.ts
trackler-2.2.1.172 tracks/typescript/exercises/protein-translation/protein-translation.example.ts
trackler-2.2.1.171 tracks/typescript/exercises/protein-translation/protein-translation.example.ts
trackler-2.2.1.170 tracks/typescript/exercises/protein-translation/protein-translation.example.ts
trackler-2.2.1.169 tracks/typescript/exercises/protein-translation/protein-translation.example.ts
trackler-2.2.1.167 tracks/typescript/exercises/protein-translation/protein-translation.example.ts
trackler-2.2.1.166 tracks/typescript/exercises/protein-translation/protein-translation.example.ts
trackler-2.2.1.165 tracks/typescript/exercises/protein-translation/protein-translation.example.ts
trackler-2.2.1.164 tracks/typescript/exercises/protein-translation/protein-translation.example.ts
trackler-2.2.1.163 tracks/typescript/exercises/protein-translation/protein-translation.example.ts
trackler-2.2.1.162 tracks/typescript/exercises/protein-translation/protein-translation.example.ts
trackler-2.2.1.161 tracks/typescript/exercises/protein-translation/protein-translation.example.ts
trackler-2.2.1.160 tracks/typescript/exercises/protein-translation/protein-translation.example.ts