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.78 tracks/javascript/exercises/proverb/example.js
trackler-2.2.1.77 tracks/javascript/exercises/proverb/example.js
trackler-2.2.1.76 tracks/javascript/exercises/proverb/example.js
trackler-2.2.1.75 tracks/javascript/exercises/proverb/example.js
trackler-2.2.1.74 tracks/javascript/exercises/proverb/example.js
trackler-2.2.1.73 tracks/javascript/exercises/proverb/example.js
trackler-2.2.1.72 tracks/javascript/exercises/proverb/example.js
trackler-2.2.1.71 tracks/javascript/exercises/proverb/example.js
trackler-2.2.1.70 tracks/javascript/exercises/proverb/example.js
trackler-2.2.1.69 tracks/javascript/exercises/proverb/example.js
trackler-2.2.1.68 tracks/javascript/exercises/proverb/example.js
trackler-2.2.1.67 tracks/javascript/exercises/proverb/example.js
trackler-2.2.1.66 tracks/javascript/exercises/proverb/example.js
trackler-2.2.1.65 tracks/javascript/exercises/proverb/example.js
trackler-2.2.1.64 tracks/javascript/exercises/proverb/example.js
trackler-2.2.1.63 tracks/javascript/exercises/proverb/example.js
trackler-2.2.1.62 tracks/javascript/exercises/proverb/example.js
trackler-2.2.1.61 tracks/javascript/exercises/proverb/example.js
trackler-2.2.1.60 tracks/javascript/exercises/proverb/example.js
trackler-2.2.1.59 tracks/javascript/exercises/proverb/example.js