I am having some calc inconsistency when trying to figure out some averages. Apparently I am doing something wrong, but I cannot figure it out.
I have an array of speed samples example:
[3.3, 3.3, 3.32, 3.32, 3.22, 3.22, 3.14, 3.14, 3, 3, 3, 3, 3.02, 3.02, 2.96, 2.96, 2.92, 2.92, 2.88, 2.88, 2.88, 2.88, 2.86, 2.86, 2.86, 2.86, 2.86, 2.86, 2.88, 2.88, 2.88, 2.88, 2.86, 2.86, 2.84, 2.84, 2.86, 2.86, 2.88, 2.88, 2.9, 2.9, 2.86, 2.86, 2.84, 2.84, 2.84, 2.84, 2.82, 2.82, 2.8, 2.8, 2.64, 2.64, 0, 0, 2.22, 2.22, 2.3, 2.3, 2.4, 2.4, 2.44, 2.44, 2.58, 2.58, 2.6, 2.6, 2.62, 2.62, 2.62, 2.62, 2.58, 2.58, 2.54, 2.54, 2.52, 2.52, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.48, 2.48, 2.46, 2.46, 2.44, 2.44, 2.44, 2.44, 2.42, 2.42, 2.42, 2.42, 2.42, 2.42, 2.42, 2.42]
Now in order to find the average speed I do
[3.3, 3.3, 3.32, 3.32, 3.22, 3.22, 3.14, 3.14, 3, 3, 3, 3, 3.02, 3.02, 2.96, 2.96, 2.92, 2.92, 2.88, 2.88, 2.88, 2.88, 2.86, 2.86, 2.86, 2.86, 2.86, 2.86, 2.88, 2.88, 2.88, 2.88, 2.86, 2.86, 2.84, 2.84, 2.86, 2.86, 2.88, 2.88, 2.9, 2.9, 2.86, 2.86, 2.84, 2.84, 2.84, 2.84, 2.82, 2.82, 2.8, 2.8, 2.64, 2.64, 0, 0, 2.22, 2.22, 2.3, 2.3, 2.4, 2.4, 2.44, 2.44, 2.58, 2.58, 2.6, 2.6, 2.62, 2.62, 2.62, 2.62, 2.58, 2.58, 2.54, 2.54, 2.52, 2.52, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.48, 2.48, 2.46, 2.46, 2.44, 2.44, 2.44, 2.44, 2.42, 2.42, 2.42, 2.42, 2.42, 2.42, 2.42, 2.42]
.reduce(function(acc, val) { return acc + val; }, 0)/100
The result is: (m/s)
2.670800000000001
Now to convert to pace I do
1000/2.670800000000001 = 374.41964954320787
So 374.41964954320787 seconds
Now if I first convert that array of speed values to pace with the same conversion like
speedArray.map(v => 1000/v)
I get this array
[303.03030303030306, 303.03030303030306, 301.20481927710847, 301.20481927710847, 310.55900621118013, 310.55900621118013, 318.4713375796178, 318.4713375796178, 333.3333333333333, 333.3333333333333, 333.3333333333333, 333.3333333333333, 331.12582781456956, 331.12582781456956, 337.83783783783787, 337.83783783783787, 342.4657534246575, 342.4657534246575, 347.22222222222223, 347.22222222222223, 347.22222222222223, 347.22222222222223, 349.65034965034965, 349.65034965034965, 349.65034965034965, 349.65034965034965, 349.65034965034965, 349.65034965034965, 347.22222222222223, 347.22222222222223, 347.22222222222223, 347.22222222222223, 349.65034965034965, 349.65034965034965, 352.11267605633805, 352.11267605633805, 349.65034965034965, 349.65034965034965, 347.22222222222223, 347.22222222222223, 344.82758620689657, 344.82758620689657, 349.65034965034965, 349.65034965034965, 352.11267605633805, 352.11267605633805, 352.11267605633805, 352.11267605633805, 354.6099290780142, 354.6099290780142, 357.14285714285717, 357.14285714285717, 378.78787878787875, 378.78787878787875, Infinity, Infinity, 450.45045045045043, 450.45045045045043, 434.7826086956522, 434.7826086956522, 416.6666666666667, 416.6666666666667, 409.8360655737705, 409.8360655737705, 387.5968992248062, 387.5968992248062, 384.6153846153846, 384.6153846153846, 381.6793893129771, 381.6793893129771, 381.6793893129771, 381.6793893129771, 387.5968992248062, 387.5968992248062, 393.7007874015748, 393.7007874015748, 396.8253968253968, 396.8253968253968, 400, 400, 400, 400, 400, 400, 403.2258064516129, 403.2258064516129, 406.5040650406504, 406.5040650406504, 409.8360655737705, 409.8360655737705, 409.8360655737705, 409.8360655737705, 413.22314049586777, 413.22314049586777, 413.22314049586777, 413.22314049586777, 413.22314049586777, 413.22314049586777, 413.22314049586777, 413.22314049586777]
Now running the save AVG calculation on that
Like this oo.filter(v => v !== Infinity).reduce(function(acc, val) { return acc + val; }, 0)/98
370.3021539217866
The AVG pace of those samples is:
370.3021539217866
NOTICE above the array has 2 infinity values and that is why the division with 98 not 100
Which is not the same as converting the AVG SPEED to Pace
What can I be doing wrong?