SO-35818306

by David Thomas

JavaScript

function choseBig(myArray, opts) {
  var settings = {
      'max': true,
      'howMany': 2
    };

  opts = opts || {};

  Object.keys(opts).forEach(function(o) {
    settings[o] = opts[o];
  });

  return myArray.sort((a, b) => settings.max === true ? b - a : a - b).slice(0, settings.howMany);
}

console.log(choseBig([1, 2, 3, 4, 5, 9], {
  'max': true,
  'howMany': 3
}));