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