Math.sum or a likewise, baked in API. Fear not — summing an array of numbers is easy using
const numbers = [1, 2, 3, 4]; const sum = numbers.reduce((a, b) => a + b, 0);
0 represents the starting value while with
b, one represents the running total with the other representing the value to be added. You’ll also note that using
reduce prevents side effects! I’d still prefer something like
Math.sum(...numbers) but a simple
reduce will do!
My trip to Mozilla Summit 2013 was incredible. I’ve spent so much time focusing on my project that I had lost sight of all of the great work Mozillians were putting out. MozSummit provided the perfect reminder of how brilliant my colleagues are and how much…