Sha256: 5d0825e271a351441e31125904c45bc88f24d986f2be567e480e2f99dad3562c

Contents?: true

Size: 1000 Bytes

Versions: 132

Compression:

Stored size: 1000 Bytes

Contents

'use strict';

module.exports = translate;

function translate(rnaStrand) {
  var proteins = [];

  if (rnaStrand) {
    for (var i = 0; i < rnaStrand.length; i += 3) {
      var 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;
}

function getProtein(codon) {
  switch (codon) {
  case 'AUG':
    return 'Methionine';

  case 'UUU':
  case 'UUC':
    return 'Phenylalanine';

  case 'UUA':
  case 'UUG':
    return 'Leucine';

  case 'UCU':
  case 'UCC':
  case 'UCA':
  case 'UCG':
    return 'Serine';

  case 'UAU':
  case 'UAC':
    return 'Tyrosine';

  case 'UGU':
  case 'UGC':
    return 'Cysteine';

  case 'UGG':
    return 'Tryptophan';

  case 'UAA':
  case 'UAG':
  case 'UGA':
    return 'STOP';

  default:
    return 'INVALID';
  }
}

Version data entries

132 entries across 132 versions & 1 rubygems

Version Path
trackler-2.2.1.98 tracks/javascript/exercises/protein-translation/example.js
trackler-2.2.1.97 tracks/javascript/exercises/protein-translation/example.js
trackler-2.2.1.96 tracks/javascript/exercises/protein-translation/example.js
trackler-2.2.1.95 tracks/javascript/exercises/protein-translation/example.js
trackler-2.2.1.94 tracks/javascript/exercises/protein-translation/example.js
trackler-2.2.1.93 tracks/javascript/exercises/protein-translation/example.js
trackler-2.2.1.92 tracks/javascript/exercises/protein-translation/example.js
trackler-2.2.1.91 tracks/javascript/exercises/protein-translation/example.js
trackler-2.2.1.90 tracks/javascript/exercises/protein-translation/example.js
trackler-2.2.1.89 tracks/javascript/exercises/protein-translation/example.js
trackler-2.2.1.88 tracks/javascript/exercises/protein-translation/example.js
trackler-2.2.1.87 tracks/javascript/exercises/protein-translation/example.js
trackler-2.2.1.86 tracks/javascript/exercises/protein-translation/example.js
trackler-2.2.1.85 tracks/javascript/exercises/protein-translation/example.js
trackler-2.2.1.84 tracks/javascript/exercises/protein-translation/example.js
trackler-2.2.1.83 tracks/javascript/exercises/protein-translation/example.js
trackler-2.2.1.82 tracks/javascript/exercises/protein-translation/example.js
trackler-2.2.1.81 tracks/javascript/exercises/protein-translation/example.js
trackler-2.2.1.80 tracks/javascript/exercises/protein-translation/example.js
trackler-2.2.1.79 tracks/javascript/exercises/protein-translation/example.js