by 2OEH8eoCRo0 · 3y ago · 0 comments
Good programmers play code golf, great programmers write readable and maintainable code.
Your example seems reasonable but programmers also like to act like the smartest one in the room. I often come across tricky and borderline obfuscated code because somebody wanted to look clever. This is a logistical nightmare.
Javascript (v8, last I checked) is the opposite. Simple for loops almost always outperform anything else.
Most of the time you should just write whatever's clear/convenient but sometimes it's worth trying both and scrutinizing godbolt.
My general rule is that if you need fewer lines of code to implement your logic with a simple for loop, you probably should.