MCPcopy
hub / github.com/msgbyte/tianji / sampleItems

Function sampleItems

apps/daily-ai-trigger/src/handler.ts:122–129  ·  view source on GitHub ↗

* Randomly sample a specified number of elements from an array

(items: T[], sampleSize: number)

Source from the content-addressed store, hash-verified

120 * Randomly sample a specified number of elements from an array
121 */
122function sampleItems<T>(items: T[], sampleSize: number): T[] {
123 const copy = [...items];
124 for (let i = copy.length - 1; i > 0; i--) {
125 const j = Math.floor(Math.random() * (i + 1));
126 [copy[i], copy[j]] = [copy[j], copy[i]];
127 }
128 return copy.slice(0, sampleSize);
129}

Callers 1

handleCreateDailyReportFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected