2 ms·
Let's say I have a list of friend objects: myFriends: { name: string, friends: friend[] }[] If I wanted to get a list of friends of friends, I could do someth
by beardedetim 5y ago
Let's say I have a list of friend objects:
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.