UNPKG

foxts

Version:

Opinionated collection of common TypeScript utils by @SukkaW

1 lines 500 B
"use strict";var n=require("../random-int/index.js");function e(n){return function(e,t=1){if(t>e.length)throw TypeError("Count must be lower or the same as the number of picks");const r=e.slice(),o=[];for(;t--;)1===r.length?o.push(r[0]):o.push(r.splice(n(0,r.length-1),1)[0]);return o}}const t=e(n.randomInt);function r(n){return function(e){return 1===e.length?e[0]:e[n(0,e.length-1)]}}const o=r(n.randomInt);exports.createPickOne=r,exports.createPickRandom=e,exports.pickOne=o,exports.pickRandom=t;