choice.js 421 B

123456789101112131415
  1. var randInt = require('./randInt');
  2. var isArray = require('../lang/isArray');
  3. /**
  4. * Returns a random element from the supplied arguments
  5. * or from the array (if single argument is an array).
  6. */
  7. function choice(items) {
  8. var target = (arguments.length === 1 && isArray(items))? items : arguments;
  9. return target[ randInt(0, target.length - 1) ];
  10. }
  11. module.exports = choice;