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