DEV Community

Discussion on: Why you should use Array.some instead of 'for' loop or forEach?

Collapse
 
psiho profile image
Mirko Vukušić

Yes, agree. It also needs to be said that often people overoptimize code for speed wasting readibility. In vast majority of cases it's absolutely not needed, especially not in places like this. But I'm ol school, started with assembler and only like 32 KB of memory so I got into habbit... Not to optimize every case, but to learn and know how things work and try to get good habbits, so relatively optimized code is written right from start. I admit that my treshold for wasting resources is lower :)
In practice, what I can think of are games, where each frame counts. Also, I do a lot of business apps, like erp, and sometimes I need to agregate thousands of records (like invoices) client side (because server side is external api). Splitting data when agreggating is not an option. In those cases I always go to for-loops, even if couple thousands are still not a huge reason to optimize. In thise cases, I "solve" readibility by extracting loops to helper functions which are properly named.