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

  • SEARCH
  • Home
  • 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 8930841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:59:03+00:00 2026-06-15T08:59:03+00:00

I have a disturbing case : I would like to sort a list of

  • 0

I have a disturbing case : I would like to sort a list of strings with an associated weight, like that :

@array = [{0 => "string"}, {0 => "my string"}, {2 => "my very long string which I want to match"}]

The result of the sort should be:

{2 => "my very long string which I want to match"}
{0 => "my string"}
{0 => "string"}

The first element is the very long string because the difference pound/string.length has a better percentage as others.

I tried to sort by grouping by weight, and after by strings but it doesn’t work. I also tried to calculate ratios, but I’m still not getting the right ordered list.

Thanks a lot for your answers.

  • 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-15T08:59:04+00:00Added an answer on June 15, 2026 at 8:59 am
    @array.sort_by do |h| 
      pound, string = h.first
      -pound.to_f / string.length
    end
    #=> [{2=>"my very long string which I want to match"}, {0=>"my string"}, {0=>"string"}]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Tables have been used in designing web sites for a very long time. Yet,
I'm banging my head on this one. I have a disturbing horizontal scrollbar that
I'm facing a probleme very disturbing. I have a jsp, which display a form
I'm using EF 4 on my web site and have found a very disturbing
Have a procedure which looks like Procedure TestProc(TVar1, TVar2 : variant); Begin TVar1 :=
I am trying to compile a driver that we have from source and I
i have some index.php page.. after download jquery drop down menu,the link text like
I have a form that adds rows to a table upon submit: <form id=scan_form
I have seen a disturbing trend where websites are starting to require verification sent
I have implemented a class that extends System.Timers.Timer object. When I then save the

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.