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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:47:37+00:00 2026-05-26T23:47:37+00:00

I am working on a program that will compare two .csv files. After extracting

  • 0

I am working on a program that will compare two .csv files. After extracting the relevant data from one of the csv files into an array of arrays, I need to combine related entries. For example, I would want to turn this array:

[["11/13/15", ["4001", "1392"], "INBOUND"], 
["11/13/15", ["4090", "540"], "INBOUND"], 
["11/13/15", ["1139", "162"], "INBOUND"], 
["11/13/15", ["1158", "64"], "INBOUND"], 
["11/13/15", ["4055", "352"], "OUTBOUND"], 
["11/13/15", ["4055", "448"], "OUTBOUND"], 
["11/13/15", ["4055", "352"], "OUTBOUND"], 
["11/13/15", ["1139", "162"], "OUTBOUND"], 
["11/13/15", ["1158", "64"], "OUTBOUND"], 
["11/13/15", ["4091", "520"], "OUTBOUND"]]

into this:

[["11/13/15", ["4001", "1392"], "INBOUND"], 
["11/13/15", ["4090", "540"], "INBOUND"], 
["11/13/15", ["1139", "162"], "INBOUND"], 
["11/13/15", ["1158", "64"], "INBOUND"], 
["11/13/15", ["4055", "1152"], "OUTBOUND"], 
["11/13/15", ["1139", "162"], "OUTBOUND"], 
["11/13/15", ["1158", "64"], "OUTBOUND"], 
["11/13/15", ["4091", "520"], "OUTBOUND"]]

For some element of the array, if its items at [0], [1][0], and [2] match those of another one, then create a new item (array) with its item at [1][1] being the sum of all the items at [1][1] and delete the old arrays. If it would be easier, I can change the way the relevant data is extracted so that the item at [1] is not an array and each row has 4 items instead of 3.

  • 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-26T23:47:38+00:00Added an answer on May 26, 2026 at 11:47 pm

    I assume that the elements to group are consecutive so we can use Enumerable#chunk. Functional approach:

    grouped_xs = xs.chunk { |date, (id1, id2), direction| [date, id1, direction] }
    grouped_xs.map do |(date, id1, direction), ary|
      id2_sum = ary.map { |date, (id1, id2), direction| id2.to_i }.inject(:+)
      [date, id1, id2_sum.to_s, direction]
    end
    

    Output (you wanted 4 elements in the output array, right?):

    [["11/13/15", "4001", "1392", "INBOUND"],
     ["11/13/15", "4090", "540", "INBOUND"],
     ["11/13/15", "1139", "162", "INBOUND"],
     ["11/13/15", "1158", "64", "INBOUND"],
     ["11/13/15", "4055", "1152", "OUTBOUND"],
     ["11/13/15", "1139", "162", "OUTBOUND"],
     ["11/13/15", "1158", "64", "OUTBOUND"],
     ["11/13/15", "4091", "520", "OUTBOUND"]]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a program that will eventually compare two .csv files and
I am working on a parsing program that parses info from two files into
I'm working on a program that will sort files based on extension I currently
I'm working a program that will have a bunch of threads processing data. Each
Is there a program that will print a nicely formatted tree from XML data?
I'm working on a python program that will automatically combine sets of files based
I'm working on a program that will tell what level a programmer is at
I'm working on a program that will need to delete a folder (and then
I am working on a background program that will be running for a long
I'm working on a Google App Engine program that will require some basic spell

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.