Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
What do you use when you want to summate something or fill a dictionary from an array?
-
I've have to look up the differences between map reduce and filter way way way too often.
-
@N00bPancakes
Just mentally replace the word reduce with fold. It folds the result of an n-value series into a single resulting value. It folds a series of value together.
Filter just returns an array that is all values from the source array where the predicate returned true. -
@lamka02sk
I think it is more of a semantic satiation thing.
I use map, filter, every day. Less so reduce.
But then I type out another one and ... it just occurs to me I'm in zombie mode, the method syntax is similar, I start wonder about the vastness of the universe, and maybe not entirely sure what the difference is between them ;) -
@SortOfTested Your mentioned usecase is one of the few where reduce is appropriate.
I see it abused wher a map, find, filter or loop would have been the right choice. -
@PonySlaystation
Had to check, lots of readability trolls on the internet who don't like declarative programming in any context ;)
Appropriateness does indeed matter. Usually, if you're side effecting, you should avoid the declarative method. Though I personally thing you should avoid side effecting in pretty much every case.
@N00bPancakes
Got bored in a pointless sales meeting, so I wrote up an example primer-as-code on it, with some other goodies thrown in.
https://stackblitz.com/edit/... -
It's useful, and maybe the only possible one-liner for finding sum of an array, It might be difficult to read, but if you are using JS, understanding it is a better option than not using it.
-
@SortOfTested Thanks! I think I'll have to unpack some of the RxJS and Observable to figure this out entirely ;)
-
@N00bPancakes
The reason I like that approach is because of how broken the JS declarative array fns are.
Each function will produce an entirely new array buffer for each operation. This results in a significiantly greater space complexity than you would usually expect from a streamlike interface.
Rx will apply every operator to each value before the next value is processed, so the space complexity is always 1n.
Related Rants
-
justamuslimguy20All the stupid date functions where the days range from 1 to 31 but the months range from 0 to 11
-
sudo-woodo16Whatever the fuck Python's ternary operator syntax is supposed to be.
-
Root18Most hated language features? PL/SQL: • it exists XSLT: • it also exists PHP: • it still exists. VB:...
I kind of hate people who use the JavaScript array method Array.reduce(...)
It rarely makes sense but makes code unnecessarily complex to read.
rant
reduce pp size
wk229