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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:41:53+00:00 2026-05-29T11:41:53+00:00

I have a rather unique problem that I’m having trouble solving. I have a

  • 0

I have a rather unique problem that I’m having trouble solving. I have a 2 x 3 table, arranged like shown below.

    _1____2__
1-|____|____|
2-|____|____|
3-|____|____|

Data is populated into the cells of the table. Sometimes, the data in a column or row can be the same. For example, if (1,1) and (1,2) have the same data. In some cases (1,1), (1,2), and (1,3) can all have the same data. If the values in the cells are the same, and adjacent, they need to be merged. For example, if (1,1) and (1,2) both have a value of “100”, the two cells get merged. I’ve done this manually by using jquery like:

(1,2).hide();
(1,1).attr("rowspan", "2");

I hide the (1,2) cell instead of delete, since the tables can be reset to the original 2×3 and then repopulated if needed. Manually, this works great, but I need a dynamic method. Below is the overall goal of what needs to be accomplished.

  • If two vertically adjacent cells or three vertically adjacent cells in their respective columns have a values that are equal, then those cells are merged together.
  • Row cells, like (1,1) and (2,1) can have duplicated data, and are never merged.
  • For reference, the groups of cells that are compatible to be merged are {(1,1),(1,2)}, {(1,1),(1,2),(1,3)}, {(1,2),(1,3)}, {(2,1),(2,2)}, {(2,1),(2,2),(2,3)}, {(2,2),(2,3)}
  • Multiple merges can happen at a time. For example: {(1,1),(1,2)} have the same data, and {(2,1),(2,2),(2,3)} have the same data. Both groups are individually merged.

My main question is, how would I go about writing an algorithm to do this, without writing out every possible situation. Can someone show me an example of something that would work? I realize this is complex, so feel free to ask questions for clarification. Thanks so much in advanced. This is a huge help!

  • 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-29T11:41:54+00:00Added an answer on May 29, 2026 at 11:41 am

    Like this? http://jsfiddle.net/4zGvg/
    Works with arbitrary rows/cols.

    The idea: we have values matrix and span matrix. The values of span are

    0 = hide this cell

    1 = normal cell

    x > 1 = cell with rowspan x

    Iterate by columns in direct order and by rows in reverse order. If some cell’s value is equal to the value below it, increase this cell’s span and delete the span of the below cell:

    for (var col = 0; col < cols; col++) {
        for (var row = rows - 2; row >= 0; row--) {
            if (values[row][col] == values[row + 1][col]) {
                span[row][col] = span[row + 1][col] + 1;
                span[row + 1][col] = 0;
            }
        }
    }
    

    Once this is done, you can use span to generate the complete table or to show/hide cells and set their rowspan attributes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a rather silly problem. I'll simplify the situation: I have a table
I have a rather large (many gigabytes) table of data in SQL Server that
I have rather large input XML files that must be converted to a given
I have a rather big number of source files that I need parse and
I have a rather simple informational website that's being run by Django. Its' pages(views)
I've got a rather tricky problem that I've been trying to solve for the
I have a classification problem where I would like to predict an outcome, but
I am currently working on a problem that I have an inelegant solution for.
I have the problem that I will have multiple servers that perform jobs. They
I have a very simple problem and a solution that will work, but I'm

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.