foxts
Version:
Opinionated collection of common TypeScript utils by @SukkaW
2 lines (1 loc) • 455 B
JavaScript
import{randomInt as e}from"./random-int.mjs";function t(e){return function(t,n=1){if(n>t.length)throw TypeError("Count must be lower or the same as the number of picks");let r=t.slice(),o=[];for(;n--;)1===r.length?o.push(r[0]):o.push(r.splice(e(0,r.length-1),1)[0]);return o}}let n=t(e);function r(e){return function(t){return 1===t.length?t[0]:t[e(0,t.length-1)]}}let o=r(e);export{r as createPickOne,t as createPickRandom,o as pickOne,n as pickRandom};