MCPcopy
hub / github.com/Shopify/flash-list / addValue

Method addValue

src/utils/AverageWindow.ts:28–43  ·  view source on GitHub ↗

* * @param value Add new value to the average window and updated current average

(value: number)

Source from the content-addressed store, hash-verified

26 * @param value Add new value to the average window and updated current average
27 */
28 public addValue(value: number): void {
29 const target = this.getNextIndex();
30 const oldValue = this.inputValues[target];
31 const newCount =
32 oldValue === undefined ? this.currentCount + 1 : this.currentCount;
33
34 this.inputValues[target] = value;
35
36 this.currentAverage = Math.max(
37 0,
38 this.currentAverage * (this.currentCount / newCount) +
39 (value - (oldValue ?? 0)) / newCount
40 );
41
42 this.currentCount = newCount;
43 }
44
45 private getNextIndex(): number {
46 // starts from 0 once we reach end of the array

Callers 5

addValueMethod · 0.45
markRenderCompleteMethod · 0.45
fillAverageWindowFunction · 0.45

Calls 1

getNextIndexMethod · 0.95

Tested by 1

fillAverageWindowFunction · 0.36