.some and .every are amazing too, also .reduce. All the functors rock. Also Array.from
This is a nifty trick too, pass a Boolean construtor to clean an array of all falsely or holes, return only truthy values.
["", 0, "HEY", , null, -Infinity]
.filter(Boolean) // => ["Hey"]
Lastly .find is just like filter but returns one value rather than an array.
I think all the functors are based on reduce.
This is functional programming where this expression is preferred over statements like if and for. You will be surprised how much you can get away with.
A functor in FP is the thing that is mapped over (a typeclass with an fmap implementation in Haskell), not the function that gets applied. What you refer to as “functors” are higher-order functions.
Groovy well that's straightend out. 😅
Incredible how there's still things to learn. I will definitely start looking at ways to through in this nifty trick, and that .find too! Thanks!
Ooh! New toys! I'll have to check them and see what they do.
They're amazing. Not a day goes by without me writing one of these! I love how easy they are to write and how understandable they are to read afterwards to know what a piece of code does.
I was about to say that, if you like map and filter, you'll love reduce, but it's been said...
I've looked at it a bit, but I think it'll be tomorrow's trouble, hehe
It'll be there when you get to it.
In my language of choice, Perl, map exists, filter is grep, and reduce comes from a non-standard library. It still fills me with joy.
The explanation was neat!
Good explanation and examples! 😊
These are my enemies from today onwards.. haha
All these introduced in ES6. There are more good fun in ES6 and so on.
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.