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.159 tracks/typescript/exercises/protein-translation/protein-translation.example.ts
trackler-2.2.1.158 tracks/typescript/exercises/protein-translation/protein-translation.example.ts
trackler-2.2.1.157 tracks/typescript/exercises/protein-translation/protein-translation.example.ts
trackler-2.2.1.156 tracks/typescript/exercises/protein-translation/protein-translation.example.ts
trackler-2.2.1.155 tracks/typescript/exercises/protein-translation/protein-translation.example.ts
trackler-2.2.1.154 tracks/typescript/exercises/protein-translation/protein-translation.example.ts
trackler-2.2.1.153 tracks/typescript/exercises/protein-translation/protein-translation.example.ts
trackler-2.2.1.152 tracks/typescript/exercises/protein-translation/protein-translation.example.ts
trackler-2.2.1.151 tracks/typescript/exercises/protein-translation/protein-translation.example.ts
trackler-2.2.1.150 tracks/typescript/exercises/protein-translation/protein-translation.example.ts
trackler-2.2.1.149 tracks/typescript/exercises/protein-translation/protein-translation.example.ts
trackler-2.2.1.148 tracks/typescript/exercises/protein-translation/protein-translation.example.ts
trackler-2.2.1.147 tracks/typescript/exercises/protein-translation/protein-translation.example.ts
trackler-2.2.1.146 tracks/typescript/exercises/protein-translation/protein-translation.example.ts
trackler-2.2.1.145 tracks/typescript/exercises/protein-translation/protein-translation.example.ts
trackler-2.2.1.144 tracks/typescript/exercises/protein-translation/protein-translation.example.ts
trackler-2.2.1.143 tracks/typescript/exercises/protein-translation/protein-translation.example.ts
trackler-2.2.1.142 tracks/typescript/exercises/protein-translation/protein-translation.example.ts
trackler-2.2.1.141 tracks/typescript/exercises/protein-translation/protein-translation.example.ts
trackler-2.2.1.140 tracks/typescript/exercises/protein-translation/protein-translation.example.ts