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.119 tracks/javascript/exercises/proverb/example.js
trackler-2.2.1.118 tracks/javascript/exercises/proverb/example.js
trackler-2.2.1.117 tracks/javascript/exercises/proverb/example.js
trackler-2.2.1.116 tracks/javascript/exercises/proverb/example.js
trackler-2.2.1.115 tracks/javascript/exercises/proverb/example.js
trackler-2.2.1.114 tracks/javascript/exercises/proverb/example.js
trackler-2.2.1.113 tracks/javascript/exercises/proverb/example.js
trackler-2.2.1.111 tracks/javascript/exercises/proverb/example.js
trackler-2.2.1.110 tracks/javascript/exercises/proverb/example.js
trackler-2.2.1.109 tracks/javascript/exercises/proverb/example.js
trackler-2.2.1.108 tracks/javascript/exercises/proverb/example.js
trackler-2.2.1.107 tracks/javascript/exercises/proverb/example.js
trackler-2.2.1.106 tracks/javascript/exercises/proverb/example.js
trackler-2.2.1.105 tracks/javascript/exercises/proverb/example.js
trackler-2.2.1.104 tracks/javascript/exercises/proverb/example.js
trackler-2.2.1.103 tracks/javascript/exercises/proverb/example.js
trackler-2.2.1.102 tracks/javascript/exercises/proverb/example.js
trackler-2.2.1.101 tracks/javascript/exercises/proverb/example.js
trackler-2.2.1.100 tracks/javascript/exercises/proverb/example.js
trackler-2.2.1.99 tracks/javascript/exercises/proverb/example.js