Basic statistics calculation module in Javascript