Matthew
@matthew
TIL you can just do .filter(Boolean) instead of .filter((prop) => !!prop)
6 replies
1 recast
20 reactions
dylan
@dylsteck.eth
i haven't used this syntax before but saw it in a repo the other week and was surprised it exists -- much cleaner IMO
1 reply
1 recast
2 reactions
jtgi
@jtgi
something sweet about passing functions direct to filter, even others like: users.filter(isPremium) posts.map(hydrateCast)
1 reply
0 recast
1 reaction
Darryl Yeo 🛠️
@darrylyeo
It’s obsolete as of yesterday’s TypeScript candidate release, but I had an `isTruthy` helper function wrapping `Boolean()` that included proper type narrowing too.
1 reply
0 recast
1 reaction
kevin
@kevinoconnell
yeah filter boolean is goated
0 reply
0 recast
0 reaction
Royal
@royalaid.eth
Oh that's kinda cute, it's like an Object construction form of a type cast
0 reply
0 recast
0 reaction
Juuso
@juuso
History tid-bit: APL from the 1960's started using arrays made of 0 and 1 as a "view array". When you overlay an array with a view array on top of each other, the resulting array only has elements where the view array has an element 1 at a given index. This is denoted simply as /. So, 0 1 1 0 / 1 2 3 4 outputs 2 3.
0 reply
0 recast
0 reaction