JSFiddle - React, Tailwind, and code Playground
by nynexman4464
JavaScript
const alphabet = 'abcdefghijklmnopqrstuvwxyz';
const numbers = [...Array(1000).keys()];
function *makeRange(start=0,end=Infinity,step=1){
for(i=start;i<end;i+=step){
yield i;
}
return;
}
function sample(input, k){
let resevoir = [];
let i=0;
for(let x of input){
if(i>=k){
const j = Math.floor(Math.random()*i);
if(j<k-1){
resevoir[j] = x;
}
}else{
resevoir.push(x);
}
++i;
}
return resevoir;
}