Comparing an array of users to an array of structs with user object as attribute, and returning matc

Posted by keruilin on Stack Overflow See other posts from Stack Overflow or by keruilin
Published on 2010-05-16T21:31:23Z Indexed on 2010/05/16 21:40 UTC
Read the original article Hit count: 156

Filed under:
|
|
|
|

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.

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby