rolling/running statistics in javascript