Packages
A web application in pursuit of meaning in life.
Retired package: Complete rewrite, scratch old versions
Current section
Files
Jump to
Current section
Files
assets/node_modules/mout/random/choice.js
var randInt = require('./randInt');
var isArray = require('../lang/isArray');
/**
* Returns a random element from the supplied arguments
* or from the array (if single argument is an array).
*/
function choice(items) {
var target = (arguments.length === 1 && isArray(items))? items : arguments;
return target[ randInt(0, target.length - 1) ];
}
module.exports = choice;