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 8254855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:20:01+00:00 2026-06-08T01:20:01+00:00

Im having trouble sorting a multidimensional array in ruby and can’t find any question

  • 0

Im having trouble sorting a multidimensional array in ruby and can’t find any question similar to my problem. I have an array/hash or both? (excuse me as im coming from a c/php/java background and this is my first time using Ruby)

user['shapeshifter'] = {age => '25', country => 'Australia'}
user['user2'] = {age => '29', country => 'Australia'}
user['user3'] = {age => '21', country => 'Russia'}

i want to sort the user array based on age.

  • 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-06-08T01:20:02+00:00Added an answer on June 8, 2026 at 1:20 am

    You need a hash of hashes, and ruby 1.9.2 for sorted hashes, IIRC. This was covered in Sort hash by key, return hash in Ruby

    Assuming your test case, fixed so it is valid:

    user = {}
    user['shapeshifter'] = {:age => 25, :country => 'Australia'}
    user['user2'] = {:age => 29, :country => 'Australia'}
    user['user3'] = {:age => 21, :country => 'Russia'}
    

    All it takes is:

    user.sort_by {|key,value| value[:age]}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having trouble sorting an array that includes undefined elements (a sparse array)
I'm having trouble sorting an array according to another array. I've tried usort, uksort
having trouble coming up with search parameters for this issue, so I can't find
Having Trouble with Entity Framework. I have been populating EntityReferences with an EntityKey inorder
I´m having a little bit of trouble sorting a way to manage automatic resolved
I'm using the Facebook AS3 API and I'm having trouble sorting friends by relationship_status.
I'm having a little bit of trouble sorting out the paging scenario with a
I am having trouble sorting out a query (making me nuts) if you look
I'm having trouble sorting a single-column table in Rails. Each row represents a single
Having trouble with a query to return the newest order of any grouped set

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.