MCPcopy
hub / github.com/apify/crawlee / weightedAvg

Function weightedAvg

packages/utils/src/internals/general.ts:114–125  ·  view source on GitHub ↗
(arrValues: number[], arrWeights: number[])

Source from the content-addressed store, hash-verified

112 * @ignore
113 */
114export function weightedAvg(arrValues: number[], arrWeights: number[]): number {
115 const result = arrValues
116 .map((value, i) => {
117 const weight = arrWeights[i];
118 const sum = value * weight;
119
120 return [sum, weight];
121 })
122 .reduce((p, c) => [p[0] + c[0], p[1] + c[1]], [0, 0]);
123
124 return result[0] / result[1];
125}
126
127/**
128 * Returns a `Promise` that resolves after a specific period of time. This is useful to implement waiting

Callers 2

evaluateLoadSignalSampleFunction · 0.90
general.test.tsFile · 0.90

Calls 2

reduceMethod · 0.80
mapMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…