mirror of
https://github.com/ThomasJockin/readexpro.git
synced 2024-09-11 10:26:46 +03:00
20 lines
444 B
JavaScript
20 lines
444 B
JavaScript
|
|
export function sample(array,size) {
|
|
const results = [],
|
|
sampled = {};
|
|
|
|
while(results.length < size && results.length < array.length) {
|
|
const index = Math.trunc(Math.random() * array.length);
|
|
if(!sampled[index] && array[index].length >= 6) {
|
|
results.push(index);
|
|
sampled[index] = true;
|
|
}
|
|
}
|
|
|
|
return results;
|
|
}
|
|
|
|
export function randomNumber (array) {
|
|
return Math.floor(Math.random() * array.length/4)
|
|
}
|