Computes an average of an array with a set of weights applied.
Weights can be provided as an array, expected to be on 0..1 scale, with indexes
matched up to input data. Ie. data at index 2 will be weighed by index 2 in the weightings array.
// All items weighted evenly averageWeighted([1,2,3], [1,1,1]); // 2
// First item has full weight, second half, third quarter averageWeighted([1,2,3], [1, 0.5, 0.25]); // 1.57
// With reversed weighting of [0.25,0.5,1] value is 2.42
A function can alternatively be provided to compute the weighting based on array index, via weight.
Computes an average of an array with a set of weights applied.
Weights can be provided as an array, expected to be on 0..1 scale, with indexes matched up to input data. Ie. data at index 2 will be weighed by index 2 in the weightings array.
A function can alternatively be provided to compute the weighting based on array index, via weight.
This is the same as: