Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 872601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:48:29+00:00 2026-05-15T10:48:29+00:00

I have an algorithm that searches through all of my sites users, finding those

  • 0

I have an algorithm that searches through all of my sites users, finding those which share a common property with the user using the algorithm (by going to a certain page). It can find multiple users, each can have multiple shared properties. The algorithm works fine, in terms of finding the matches, but I’m having trouble working out how to store the data so that later I’ll be able to use each unit of information. I need to be able to access both the found users, and each of the respective shared properties, so I can’t just build a string. This is an example of the output, being run from the perspective of user 1:

user 4
sharedproperty3
sharedproperty6

user 6
sharedproperty6
sharedproperty10
shareproperty11

What do I need to do to be able to store this data, and have access to any bit of it for further manipulation? I was thinking of a hash of a hash, but I can’t really wrap my head around it. I’m pretty new to programming, and Ruby in particular. Thanks for reading!

EDIT – Here’s the code. I’m fully expecting this to be the most incorrect way to do this, but it’s my first try so be gentle 🙂
So if I’m understanding you guys correctly, instead of adding the interests to a string, I should be creating an array or a hash, adding each interest as I find it, then storing each of these in an array or hash? Thanks so much for the help.

def getMatchedUsers
  matched_user_html = nil
  combined_properties = nil
  online_user_list = User.logged_in.all
    shared_interest = false
    online_user_list.each do |n| # for every online user
      combined_properties = nil
      if n.email != current_user.email # that is not the current user 
      current_user.properties.each do |o| # go through all of the current users properties
        n.properties.each do |p| # go through the online users properties
              if p.interestname.eql?(o.interestname) # if the online users property matches the current user
                  shared_interest = true
                  if combined_properties == nil
                    combined_properties = o.interestname
                  else
                    combined_properties = combined_properties + ", " + o.interestname
                  end
              end
          end
          if shared_interest == true
                matched_user_html = n.actualname + ": " + combined_properties
            end
      end
    end
    end
    return matched_user_html
  render :nothing => true
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T10:48:29+00:00Added an answer on May 15, 2026 at 10:48 am

    This returns an array of hashes with all users and their corresponding sharedproperties.

    class User
      def find_matching_users
        returning Array.new do |matching_users|
          self.logged_in.each do |other_user|
            next if current_user == other_user # jump if current_user
            # see http://ruby-doc.org/core/classes/Array.html#M002212 for more details on the & opreator
            unless (common_properties = current_user.properties & other_user.properties).empty?
              matching_users << { :user => other_user, :common_properties => common_properties }
            end
          end
        end
      end
    end
    

    In your view you can do something like this:

    <%- current_user.find_matching_users.each do |matching_user| -%>
      <%-# you can acccess the user with matching_user[:user] -%>
      <%-# you can acccess the common properties with matching_user[:common_properties] -%>
    <%- end -%>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an algorithm that generates strings based on a list of input words.
I have an algorithm that recursively makes change in the following manner: public static
I have this algorithm that I want to implement on VB6. Sub Main() dim
If I have an algorithm that takes n log n steps (e.g. heapsort), where
I have a two part question Best-Practice I have an algorithm that performs some
Suppose I have: Toby Tiny Tory Tily Is there an algorithm that can easily
I have a SP that has the following algorithm. IF <SomeCondition> BEGIN SELECT *
Does anybody have any reference material that details Cauchy-Reed algorithm? Googling for Cauchy-Reed Solomon
i have heard from a friend of mine that the best algorithm for swapping
It is known that google has best searching & indexing algorithm. The also have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.