UNPKG

svcorelib

Version:

Core library used in the projects of Sv443 and the Sv443 Network. Contains tons of miscellaneous QoL features.

18 lines (12 loc) 360 B
const randomItemIndex = require("./randomItemIndex"); function takeRandomItem(arr) { if(!Array.isArray(arr)) throw new Error("Parameter is not an array"); if(arr.length === 0) return undefined; const [itm, idx] = randomItemIndex(arr); arr.splice(idx, 1); return itm; } module.exports = takeRandomItem;