DEV Community

Discussion on: 1 line of code: How to get the average of an array

 
martinkr profile image
Martin Krause

Logically yes, but it's like 10% faster - also at the url you set up - with an initial 0 for me.

Thread Thread
 
jonrandy profile image
Jon Randy 🎖️ • Edited

On the link above (all tests on my macbook) - Chrome has near identical speed for both functions (occasionally the first will be faster than the other, but also sometimes the second). On Firefox, the second function is always faster. So, on balance it seems that without initialising the 0 is faster overall (as logically expected). The JS engine in Chrome is clearly doing some smarter optimisation

Update: Just tried Chrome and Firefox on Ubuntu too - same results as for the macbook

Thread Thread
 
martinkr profile image
Martin Krause

Hmm ... let's say ... we'll just go with the logic and I'll update the article and the code. :D
Thank you for your time and investigations.