Skip to main content
8 events
when toggle format what by license comment
Sep 12, 2017 at 21:54 comment added BenC @IgorSoloydenko To expand, the shortest version is actually .filter(x => x), which does the boolean conversion implicitly, but .filter(Boolean) is more explicit, reads a bit nicer, and is pointfree in case you get a kick out of that.
Sep 12, 2017 at 20:55 comment added Igor Soloydenko @Slai makes sense now. Thanks. I did not know that a) the compressed syntax without an arrow is meaningful; b) Boolean has a ctor with any as an argument.
Sep 12, 2017 at 20:54 comment added Slai @IgorSoloydenko like in C#, instead of lambda .filter(item => Boolean(item)), the method can be passed directly .filter(Boolean)
Sep 12, 2017 at 19:12 comment added Igor Soloydenko @BenC nice answer. Could you please explain the machinery of the .filter(Boolean)? I see this the second time, so I assume this is idiomatic to JS, but I am still not sure how does it work under the hood.
Sep 12, 2017 at 6:44 comment added BenC Glad you found it useful. In the future, feel free to wait a little while before accepting an answer, in case anyone else chimes in with something better! :)
Sep 12, 2017 at 6:32 comment added Sam Fantastic response! Really appreciate the explanations. You literally demonstrated the chaining of functions and using lots of short hand. Also avoided using temp variables. That's exactly what I was referring to. Based on your version of the code, my C# accent is not so subtle but I appreciate your being kind :-) Thanks again!
Sep 12, 2017 at 6:29 vote accept Sam
Sep 12, 2017 at 6:23 history answered BenC CC BY-SA 3.0