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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:32:41+00:00 2026-05-15T18:32:41+00:00

I have any array of structs. Each struct in the array has the following

  • 0

I have any array of structs. Each struct in the array has the following attributes:

  1. user_id
  2. num_hot_dogs_eaten
  3. date_last_pigged_out

Here’s what I want to do:

  1. Find the structs with matching user_id’s, and merge them into one struct record where num_hot_dogs_eaten is the sum of all matching records and date_last_pigged_out is the most-recent date the user pigged out.

  2. Sort the array of structs by num_hot_dogs_eaten (first order of priority) and by date_last_pigged_out (second order of priority…most-recent first).

  3. Return a new sorted array of structs.

  • 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-15T18:32:41+00:00Added an answer on May 15, 2026 at 6:32 pm

    Use this:

    def f(users)
      r = []
      users.each do |u|
        new_match = false
        match = r.find {|x| x.user_id == u.user_id }
        unless match
          match = u.dup
          r << match
          new_match = true
        end
        match.num_hot_dogs_eaten += u.num_hot_dogs_eaten unless new_match
        match.date_last_pigged_out =
          [match, u].max_by(&:date_last_pigged_out).date_last_pigged_out
      end
      r.sort_by {|u| [u.num_hot_dogs_eaten, u.date_last_pigged_out] }.
        reverse
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 523k
  • Answers 523k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I can see two advantages to using an enum. First,… May 16, 2026 at 9:40 pm
  • Editorial Team
    Editorial Team added an answer add this line if($(this).is(":animated")) return; (after event.preventDefault();) May 16, 2026 at 9:40 pm
  • Editorial Team
    Editorial Team added an answer You have not stated the complexity of the user system… May 16, 2026 at 9:40 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Here is the situation: I have got the array of bytes containing the bitmap
Say I have a list of integers, where each element is a number from
I have a C (not C++) struct that goes like this typedef struct mystruct{
I'm trying to implement a ring buffer with the following struct /*head, tail are
I have a 2D array that I need to be able to convert to
Does MATLAB have any support for hash tables? Some background I am working on
I have the $validate variable in my model which contains: var $validate=array( username =>
I have created a dynamic typing system in C in order to create a
I have some C code that is something of a puzzle. For a reason
In C# (and Java) a string is little more than a char array with

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.