Reputation: 17532
I have an array of users who are friends. Let us call this array:
friends
I then have an array of structs. Each struct has a user object as an attribute (it also has a rank attribute). Here's what the struct class looks like, to add some context:
class Leader < Struct.new(:rank, :user); end
Let us call this array of structs:
all_leaders_plus_rank
I want to compare friends and all_leaders_plus_rank, and add the match from all_leaders_plus_rank to a new array of structs called friendly_leaders.
Upvotes: 0
Views: 138
Reputation: 370357
friendly_leaders = all_leaders_plus_rank.select do |lpr|
friends.include?(lpr.user)
end
Upvotes: 0