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.139 tracks/javascript/exercises/pig-latin/example.js
trackler-2.2.1.138 tracks/javascript/exercises/pig-latin/example.js
trackler-2.2.1.137 tracks/javascript/exercises/pig-latin/example.js
trackler-2.2.1.136 tracks/javascript/exercises/pig-latin/example.js
trackler-2.2.1.135 tracks/javascript/exercises/pig-latin/example.js
trackler-2.2.1.134 tracks/javascript/exercises/pig-latin/example.js
trackler-2.2.1.133 tracks/javascript/exercises/pig-latin/example.js
trackler-2.2.1.132 tracks/javascript/exercises/pig-latin/example.js
trackler-2.2.1.131 tracks/javascript/exercises/pig-latin/example.js
trackler-2.2.1.130 tracks/javascript/exercises/pig-latin/example.js
trackler-2.2.1.129 tracks/javascript/exercises/pig-latin/example.js
trackler-2.2.1.128 tracks/javascript/exercises/pig-latin/example.js
trackler-2.2.1.127 tracks/javascript/exercises/pig-latin/example.js
trackler-2.2.1.126 tracks/javascript/exercises/pig-latin/example.js
trackler-2.2.1.125 tracks/javascript/exercises/pig-latin/example.js
trackler-2.2.1.124 tracks/javascript/exercises/pig-latin/example.js
trackler-2.2.1.123 tracks/javascript/exercises/pig-latin/example.js
trackler-2.2.1.122 tracks/javascript/exercises/pig-latin/example.js
trackler-2.2.1.121 tracks/javascript/exercises/pig-latin/example.js
trackler-2.2.1.120 tracks/javascript/exercises/pig-latin/example.js