Every story and comment from the Hacker News API, in a layout borrowed from 2001.
A comment on Flatten Arrays in Vanilla JavaScript with Flat() and FlatMap(). Parent comment
myFriends: { name: string, friends: friend[] }[]
If I wanted to get a list of friends of friends, I could do something like
myFriends.map(prop('friends')).flatten()
Or
myFriends.flatMap(prop('friends'))
My data is a list of lists but I really want a list of friends so I flatten.
Maybe the Friend object is poorly created/designed but often times you'll just have to deal with whatever the API gives you.
There are no comments on this comment yet.
myFriends: { name: string, friends: friend[] }[]
If I wanted to get a list of friends of friends, I could do something like
myFriends.map(prop('friends')).flatten()
Or
myFriends.flatMap(prop('friends'))
My data is a list of lists but I really want a list of friends so I flatten.
Maybe the Friend object is poorly created/designed but often times you'll just have to deal with whatever the API gives you.