UNPKG

typedash

Version:

modern, type-safe collection of utility functions

27 lines (26 loc) 685 B
// src/functions/sample/sample.ts function sample(source, count = 1) { if (source == null) { return void 0; } const sourceArray = [...source]; if (sourceArray.length === 0) { return void 0; } const sampleCount = Math.min(count, sourceArray.length); const indices = /* @__PURE__ */ new Set(); while (indices.size < sampleCount) { indices.add(Math.floor(Math.random() * sourceArray.length)); } const result = []; for (const index of indices) { result.push(sourceArray[index]); } if (result.length === 1) { return result[0]; } return result; } export { sample }; //# sourceMappingURL=out.js.map //# sourceMappingURL=chunk-OVK7SZEX.js.map