Sha256: be04abbf3f2380ea7f5587dbafbca35771feff36235510dc0528b155093b9bf6

Contents?: true

Size: 701 Bytes

Versions: 165

Compression:

Stored size: 701 Bytes

Contents

const lastArgIsOptions = (args) => {
  const last = args[args.length - 1];
  return typeof last === 'object';
};

const conclusion = (firstArg, qualifier = '') => `And all for the want of a ${qualifier}${firstArg}.`;

const proverb = (...args) => {
  let options = {};
  if (lastArgIsOptions(args)) {
    options = args.pop();
  }

  const allExceptLastArg = args.slice(0, -1);
  const chainOfEvents = allExceptLastArg.map((arg, index) => `For want of a ${arg} the ${args[index + 1]} was lost.`);

  const qualifier = options.qualifier ? `${options.qualifier} ` : options.qualifier;
  chainOfEvents.push(conclusion(args[0], qualifier));

  return chainOfEvents.join('\n');
};

export default proverb;

Version data entries

165 entries across 165 versions & 1 rubygems

Version Path
trackler-2.2.1.139 tracks/ecmascript/exercises/proverb/example.js
trackler-2.2.1.138 tracks/ecmascript/exercises/proverb/example.js
trackler-2.2.1.137 tracks/ecmascript/exercises/proverb/example.js
trackler-2.2.1.136 tracks/ecmascript/exercises/proverb/example.js
trackler-2.2.1.135 tracks/ecmascript/exercises/proverb/example.js
trackler-2.2.1.134 tracks/ecmascript/exercises/proverb/example.js
trackler-2.2.1.133 tracks/ecmascript/exercises/proverb/example.js
trackler-2.2.1.132 tracks/ecmascript/exercises/proverb/example.js
trackler-2.2.1.131 tracks/ecmascript/exercises/proverb/example.js
trackler-2.2.1.130 tracks/ecmascript/exercises/proverb/example.js
trackler-2.2.1.129 tracks/ecmascript/exercises/proverb/example.js
trackler-2.2.1.128 tracks/ecmascript/exercises/proverb/example.js
trackler-2.2.1.127 tracks/ecmascript/exercises/proverb/example.js
trackler-2.2.1.126 tracks/ecmascript/exercises/proverb/example.js
trackler-2.2.1.125 tracks/ecmascript/exercises/proverb/example.js
trackler-2.2.1.124 tracks/ecmascript/exercises/proverb/example.js
trackler-2.2.1.123 tracks/ecmascript/exercises/proverb/example.js
trackler-2.2.1.122 tracks/ecmascript/exercises/proverb/example.js
trackler-2.2.1.121 tracks/ecmascript/exercises/proverb/example.js
trackler-2.2.1.120 tracks/ecmascript/exercises/proverb/example.js