UNPKG

mingo

Version:

MongoDB query language for in-memory objects

16 lines (15 loc) 343 B
const $sample = (collection, expr, _options) => { return collection.transform((xs) => { const len = xs.length; let i = -1; return () => { if (++i === expr.size) return { done: true }; const n = Math.floor(Math.random() * len); return { value: xs[n], done: false }; }; }); }; export { $sample };