DEV Community

Discussion on: Calculating a Moving Average on Streaming Data

Collapse
 
slidenerd profile image
slidenerd • Edited

A much faster way to do that JS version is to get rid of reduce and use the plain old for loop, I could setup a JSPERF test to prove that the plain old for loop kicks ass when it comes to performance compared to map filter reduce and the other crappy ES6 methods, mentioning this since this post says "real time"

Also a better approach is
sum = sum - oldestValue
sum = sum + newestValue

where oldestValue is just beyond the moving average s period