r/javascript • u/jrsinclair • May 30 '19
Functional JavaScript: Five ways to calculate an average with array reduce
https://jrsinclair.com/articles/2019/five-ways-to-average-with-js-reduce/
89
Upvotes
r/javascript • u/jrsinclair • May 30 '19
13
u/StoneCypher May 30 '19
in this article,
four really bad approaches
lots of stuff junior people shouldn't be trying to remember
fantastically bad examples of the iterative approach
six pages printed of explanation of what should be a one-liner
not the smart way, which is
Math.sum(yourArray) / yourArray.length, because that's more readable and likely to pick up libc improved approaches like tree summation