Sha256: 72725a77c9df5fba79460a49887663b50fdd00f8f0a3e0098e61bbf0727be647

Contents?: true

Size: 1.07 KB

Versions: 141

Compression:

Stored size: 1.07 KB

Contents

module.exports = function () {
  var last = arguments[arguments.length - 1];
  var chain = Array.from(arguments);
  this.options = {};

  if (typeof last === 'object' && last.hasOwnProperty('qualifier')) {
    this.options = chain.pop();
  }

  this.chain = chain;
  this.qualifier = this.options.qualifier ? this.options.qualifier + ' ' : '';

  this.toString = function () {
    return this.chainOfEvents() + this.conclusion();
  }.bind(this);

  this.chainOfEvents = function () {
    return this.causesAndEffects().map( function (entry) {
      return 'For want of a ' + entry.cause +
        ' the '  + entry.effect + ' was lost.\n';
    } ).join('');
  }.bind(this);

  this.causesAndEffects = function () {
    return this.chain.reduce( function (array, event, index) {
      if (index < this.chain.length - 1) {
        array.push({ cause: event, effect: this.chain[index + 1] });
      }
      return array;
    }.bind(this), [] );
  }.bind(this);

  this.conclusion = function () {
    return 'And all for the want of a ' + this.qualifier + this.chain[0] + '.';
  }.bind(this);
};

Version data entries

141 entries across 141 versions & 1 rubygems

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