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.38 tracks/ecmascript/exercises/proverb/example.js
trackler-2.2.1.37 tracks/ecmascript/exercises/proverb/example.js
trackler-2.2.1.36 tracks/ecmascript/exercises/proverb/example.js
trackler-2.2.1.35 tracks/ecmascript/exercises/proverb/example.js
trackler-2.2.1.34 tracks/ecmascript/exercises/proverb/example.js
trackler-2.2.1.33 tracks/ecmascript/exercises/proverb/example.js
trackler-2.2.1.32 tracks/ecmascript/exercises/proverb/example.js
trackler-2.2.1.31 tracks/ecmascript/exercises/proverb/example.js
trackler-2.2.1.30 tracks/ecmascript/exercises/proverb/example.js
trackler-2.2.1.29 tracks/ecmascript/exercises/proverb/example.js
trackler-2.2.1.28 tracks/ecmascript/exercises/proverb/example.js
trackler-2.2.1.27 tracks/ecmascript/exercises/proverb/example.js
trackler-2.2.1.26 tracks/ecmascript/exercises/proverb/example.js
trackler-2.2.1.25 tracks/ecmascript/exercises/proverb/example.js
trackler-2.2.1.24 tracks/ecmascript/exercises/proverb/example.js
trackler-2.2.1.23 tracks/ecmascript/exercises/proverb/example.js
trackler-2.2.1.22 tracks/ecmascript/exercises/proverb/example.js
trackler-2.2.1.21 tracks/ecmascript/exercises/proverb/example.js
trackler-2.2.1.20 tracks/ecmascript/exercises/proverb/example.js
trackler-2.2.1.19 tracks/ecmascript/exercises/proverb/example.js