charades-keywords
Version:
Get random charades keywords
26 lines (22 loc) • 605 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var getRandomItems = exports.getRandomItems = function getRandomItems(qty, array) {
if (qty) {
var randomItems = [];
if (qty > array.length) {
return array;
}
while (randomItems.length < qty) {
var randomItem = array[Math.floor(Math.random() * array.length)];
// istanbul ignore next
if (!randomItems.includes(randomItem)) {
randomItems.push(randomItem);
}
}
return randomItems;
} else {
return [array[Math.floor(Math.random() * array.length)]];
}
};