Sha256: c69d4d5237f739cbb187234f38508ef7fc19f4e94add2f651fe15c21a15f034b

Contents?: true

Size: 868 Bytes

Versions: 123

Compression:

Stored size: 868 Bytes

Contents

const ACID_PROTEIN_MAP = {
  AUG: 'Methionine',
  UUU: 'Phenylalanine',
  UUC: 'Phenylalanine',
  UUA: 'Leucine',
  UUG: 'Leucine',
  UCU: 'Serine',
  UCC: 'Serine',
  UCA: 'Serine',
  UCG: 'Serine',
  UAU: 'Tyrosine',
  UAC: 'Tyrosine',
  UGU: 'Cysteine',
  UGC: 'Cysteine',
  UGG: 'Tryptophan',
  UAA: 'STOP',
  UAG: 'STOP',
  UGA: 'STOP',
};

const getProtein = codon => ACID_PROTEIN_MAP[codon] || 'INVALID';

export default function translate(rnaStrand) {
  const proteins = [];

  if (rnaStrand) {
    for (let i = 0; i < rnaStrand.length; i += 3) {
      const protein = getProtein(rnaStrand.substring(i, i + 3));

      if (protein) {
        if (protein === 'STOP') {
          break;
        }

        if (protein === 'INVALID') {
          throw new Error('Invalid codon');
        }

        proteins.push(protein);
      }
    }
  }

  return proteins;
}

Version data entries

123 entries across 123 versions & 1 rubygems

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