« first day (3315 days earlier)      last day (1624 days later) » 

11:02 PM
I have often been able to replace reduce with map and join, is that bad?
 
how would you replace the above reduce with map and join?
 
reduce is often used similar to a pocket knife... to do a lot of shit that would be better done with the proper tool.
 
Couldn't with that. But when reducing to a string, I often can use map and join. Just so happens in my use cases.
For example, I needed to convert an array of strings into a sql query string (`column-name`). I could have use reduce or simply, map(a => '`' + a + '`').join(", ")
i opted to go with map and join instead of reduce because it was one less google search to find the mdn page for reduce (I forgot how to use it).
 
well in that case yes, map and join is the right way to go
 
Why not reduce? Or does it not matter?
 
11:08 PM
Doesn't really matter, but join is a very readable function
you can glance at a map+join and understand it instantly
reduce, due to being a lot more capable, requires a little more parsing
 
I wonder which is faster...I would think reduce but not sure. (#micro_optimizations)
Yes I agree. Map and join is usually more readable. Thanks.
 
11:41 PM
 
@JBis I'd have to test it, but isn't .join(" , ") this same thing?
maybe one literal added too.
 
once devs learn about reduce it becomes the default hammer that they approach any problem with
it's probably one of the more harmful constructs to code readability
i found a function in our codebase that was essentially someFunc(arr) => arr.reduce(/*100+ lines of code*/)
 

« first day (3315 days earlier)      last day (1624 days later) »