loading...

re: how not to use reduce VIEW POST

TOP OF THREAD FULL DISCUSSION
re: I disagree. it is not 70% slower. The first example is just 15% slower. The second example you gave, building a Map is different from building an...

So in my first example of making an index, I used a map to create a multi-key array look up and it was 70% slower. Then realised DNA was probably "unique" HAHA. So yeah 70% faster if there is repetition.

In the map version: your "Do" is still 20% slower than the object version and lets face it, not that much more readable. The Map version is way faster of course.

I can and do write highly readable code that is fast. I wrap things in well-named functions that work efficiently :). Yes, those functions will often hide away performance, the same way as those core native functions do.

I just care about UX and UX tries not to be janky etc.

Readability vs performance is a hard thing to argue. Everyone has their own interpretation as of, what is readability, what is performance and why one is more important than the other etc.

I hope you have read the article I linked in the beginning. .reduce is a very vey powerful function. Simply by using it incurs readability cost. Because the reader need to figure out what it does. As oppose to using Object.fromEntries which the user knows immediately that it is constructing an object. There is nothing to "read into" to understand what it does.

I won't try to convince you because I don't think I can. But please go and try writing code this way. Maybe you will gain some new insights.

code of conduct - report abuse