Sha256: 818e22a4da281a11e91c957d068831fff7a03b573c3c85a133edb63e9dc1a414

Contents?: true

Size: 521 Bytes

Versions: 141

Compression:

Stored size: 521 Bytes

Contents

'use strict';

module.exports = {
  translate: function (english) {
    var words = english.split(' ');
    var translated = [];

    function translateWord(word) {
      var parts = word.match(/^([^aeiou]?qu|[^aeiou]*)(.+)/);
      var beginning = parts[1];
      var ending = parts[2];

      if (beginning.length === 0) {
        translated.push(word + 'ay');
      } else {
        translated.push(ending + beginning + 'ay');
      }
    }

    words.forEach( translateWord );
    return translated.join(' ');
  }
};

Version data entries

141 entries across 141 versions & 1 rubygems

Version Path
trackler-2.2.1.78 tracks/javascript/exercises/pig-latin/example.js
trackler-2.2.1.77 tracks/javascript/exercises/pig-latin/example.js
trackler-2.2.1.76 tracks/javascript/exercises/pig-latin/example.js
trackler-2.2.1.75 tracks/javascript/exercises/pig-latin/example.js
trackler-2.2.1.74 tracks/javascript/exercises/pig-latin/example.js
trackler-2.2.1.73 tracks/javascript/exercises/pig-latin/example.js
trackler-2.2.1.72 tracks/javascript/exercises/pig-latin/example.js
trackler-2.2.1.71 tracks/javascript/exercises/pig-latin/example.js
trackler-2.2.1.70 tracks/javascript/exercises/pig-latin/example.js
trackler-2.2.1.69 tracks/javascript/exercises/pig-latin/example.js
trackler-2.2.1.68 tracks/javascript/exercises/pig-latin/example.js
trackler-2.2.1.67 tracks/javascript/exercises/pig-latin/example.js
trackler-2.2.1.66 tracks/javascript/exercises/pig-latin/example.js
trackler-2.2.1.65 tracks/javascript/exercises/pig-latin/example.js
trackler-2.2.1.64 tracks/javascript/exercises/pig-latin/example.js
trackler-2.2.1.63 tracks/javascript/exercises/pig-latin/example.js
trackler-2.2.1.62 tracks/javascript/exercises/pig-latin/example.js
trackler-2.2.1.61 tracks/javascript/exercises/pig-latin/example.js
trackler-2.2.1.60 tracks/javascript/exercises/pig-latin/example.js
trackler-2.2.1.59 tracks/javascript/exercises/pig-latin/example.js