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.98 tracks/ecmascript/exercises/proverb/example.js
trackler-2.2.1.97 tracks/ecmascript/exercises/proverb/example.js
trackler-2.2.1.96 tracks/ecmascript/exercises/proverb/example.js
trackler-2.2.1.95 tracks/ecmascript/exercises/proverb/example.js
trackler-2.2.1.94 tracks/ecmascript/exercises/proverb/example.js
trackler-2.2.1.93 tracks/ecmascript/exercises/proverb/example.js
trackler-2.2.1.92 tracks/ecmascript/exercises/proverb/example.js
trackler-2.2.1.91 tracks/ecmascript/exercises/proverb/example.js
trackler-2.2.1.90 tracks/ecmascript/exercises/proverb/example.js
trackler-2.2.1.89 tracks/ecmascript/exercises/proverb/example.js
trackler-2.2.1.88 tracks/ecmascript/exercises/proverb/example.js
trackler-2.2.1.87 tracks/ecmascript/exercises/proverb/example.js
trackler-2.2.1.86 tracks/ecmascript/exercises/proverb/example.js
trackler-2.2.1.85 tracks/ecmascript/exercises/proverb/example.js
trackler-2.2.1.84 tracks/ecmascript/exercises/proverb/example.js
trackler-2.2.1.83 tracks/ecmascript/exercises/proverb/example.js
trackler-2.2.1.82 tracks/ecmascript/exercises/proverb/example.js
trackler-2.2.1.81 tracks/ecmascript/exercises/proverb/example.js
trackler-2.2.1.80 tracks/ecmascript/exercises/proverb/example.js
trackler-2.2.1.79 tracks/ecmascript/exercises/proverb/example.js