UNPKG

foxts

Version:

Opinionated collection of common TypeScript utils by @SukkaW

1 lines 467 B
import{randomInt as n}from"../random-int/index.mjs";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);function r(n){return function(e){return 1===e.length?e[0]:e[n(0,e.length-1)]}}const o=r(n);export{r as createPickOne,e as createPickRandom,o as pickOne,t as pickRandom};