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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:14:27+00:00 2026-05-25T00:14:27+00:00

I am a javascript newbie so bear with me. I have lists as so:

  • 0

I am a javascript newbie so bear with me. I have lists as so:

var list1 = ['a','b','c'];
var list2 = ['c','d','e'];
var list3 = ['f','g'];

As you see, list1 and list2 intersect at ‘c’ while list3 is disjoint from both list1 and list2.
The result should be

['a','b','c','d','e'],['f','g'] // Two arrays

We have combined list1 and list2 since they intersect while leaving list3 as is. Another example:

var list1 = ['a','b','c'];
var list2 = ['d','e','f'];
var list3 = ['f','g','a'];

Here we see list1 and list2 don’t intersect, list1 intersects with list3 at ‘a’ and list2 intersects list3 at ‘f’. So since all 3 intersect, the result returned would be:

['a','b','c','d','e','f','g'] // One array

Any help is appreciated
KA

PS: I did search the site for a similar problem and I came across one intersection of n lists via JS Its similar but doesn’t serve my use case.

  • 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-25T00:14:28+00:00Added an answer on May 25, 2026 at 12:14 am

    If you have two-list intersection and union functions, you can get what you want with this logic:

    var lists; // initialized with the lists you want to process
    var merged = [];
    for each list a in lists {
        for each list b in merged {
            if intersect(a,b) != empty {
                remove b from merged;
                a = union(a,b);
            }
        }
        add a to merged;
    }
    

    You just have to be a little careful about removing b from merged while you are looping through all the elements of merged. It might be simpler to iterate through merged from the last to the first element.
    The underscore library is a nice place to find functions for intersection and union.

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

Sidebar

Related Questions

I'm javascript newbie...please bear with me. Modified some jQuery animation code from w3c tutorial.
A JavaScript newbie here. I have this following code: function testObject(elem) { this.test =
First: I'm JavaScript newbie. So.. I have basic form with password, repeat password, email
Just another Rails newbie with a problem. I have some Javascript (dynamic) in a
A newbie question from me, please. I have a large data set that I
I`m a newbie at JavaScript trying to understand this tutorial about currying from Oreilly
I am newbie in javascript. i have one textBox and radioButton . if i
I'm totally newbie in javascript/jQuery and i have a little problem :) I'm using
hi i am newbie to javascript.... i want to synchronize scrolling of two select
I am newbie. many of javascript code start with <!-- <script type=text/javascript> <!-- and

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.