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.139 tracks/typescript/exercises/protein-translation/protein-translation.example.ts
trackler-2.2.1.138 tracks/typescript/exercises/protein-translation/protein-translation.example.ts
trackler-2.2.1.137 tracks/typescript/exercises/protein-translation/protein-translation.example.ts
trackler-2.2.1.136 tracks/typescript/exercises/protein-translation/protein-translation.example.ts
trackler-2.2.1.135 tracks/typescript/exercises/protein-translation/protein-translation.example.ts
trackler-2.2.1.134 tracks/typescript/exercises/protein-translation/protein-translation.example.ts
trackler-2.2.1.133 tracks/typescript/exercises/protein-translation/protein-translation.example.ts
trackler-2.2.1.132 tracks/typescript/exercises/protein-translation/protein-translation.example.ts
trackler-2.2.1.131 tracks/typescript/exercises/protein-translation/protein-translation.example.ts
trackler-2.2.1.130 tracks/typescript/exercises/protein-translation/protein-translation.example.ts
trackler-2.2.1.129 tracks/typescript/exercises/protein-translation/protein-translation.example.ts
trackler-2.2.1.128 tracks/typescript/exercises/protein-translation/protein-translation.example.ts
trackler-2.2.1.127 tracks/typescript/exercises/protein-translation/protein-translation.example.ts
trackler-2.2.1.126 tracks/typescript/exercises/protein-translation/protein-translation.example.ts
trackler-2.2.1.125 tracks/typescript/exercises/protein-translation/protein-translation.example.ts
trackler-2.2.1.124 tracks/typescript/exercises/protein-translation/protein-translation.example.ts
trackler-2.2.1.123 tracks/typescript/exercises/protein-translation/protein-translation.example.ts
trackler-2.2.1.122 tracks/typescript/exercises/protein-translation/protein-translation.example.ts
trackler-2.2.1.121 tracks/typescript/exercises/protein-translation/protein-translation.example.ts
trackler-2.2.1.120 tracks/typescript/exercises/protein-translation/protein-translation.example.ts