UNPKG

charades-keywords

Version:
26 lines (22 loc) 605 B
"use strict"; 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)]]; } };