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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:35:46+00:00 2026-05-22T18:35:46+00:00

Say you have two arrays (pseudo-code): arrayA = [ a, b, c, d ];

  • 0

Say you have two arrays (pseudo-code):

arrayA = [ "a", "b", "c", "d" ];
arrayB = [ "b", "c", "d", "e" ];

Is it possible to find unique items to arrayA (arrayA.a), common items (b, c, d), and unique items to arrayB (arrayB.e) using only two loops in a nested format?

We can determine the first two objectives as such:

// Loop over arrayA
for (itemA in arrayA) {

    // Loop over arrayB
    for (itemB in arrayB) {

        // Assume that arrayA.itemA does not exist in arrayB by default
        exists = false;

        // Check for matching arrayA.itemA in arrayB
        if (itemA == itemB) {

            // If true set exists variable and break the loop
            exists = true;
            break;
        }
    }

    // Tells us if an item is common
    if (exists) {
        // Do something
    }

    // The additional condition we need to determine (item is unique to array b)
    else if () {}

    // Tells us if the item is unique to arrayA
    else {
        // Do something else
    }
}

Question: Can we go a step further and determine the third condition (an item is unique to arrayB)? The trick is to be able to act on the third condition in the iteration of the first loop.

The loops can be in any format (do while, do, for, for in) and in any combination.

  • 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-22T18:35:47+00:00Added an answer on May 22, 2026 at 6:35 pm

    The second condition (item is unique to array b) will always be false, since you are iterating through items in A at that point. However, to answer your first question of building the 3 arrays with 2 loops in a nested format, here’s what I would do:

    //Set up the arrays to hold the values
    uniqueA = itemA;//copy of item A
    uniqueB = itemB;//copy of item B
    common = [];
    
    //Iterate through the arrays to populate the values
    for (itemA in arrayA) {
        for (itemB in arrayB) {
            if(itemB == itemA){
                comon.add(itemA);
                uniqueA.remove(itemA);
                uniqueB.remove(itemB);
                break;
            }
        }
    }
    

    Note You could argue that copying itemA and itemB is iterating through them. The only way I see around this is if you don’t care about keeping the initial array values and the values are unique, in which case you can use arrayA and arrayB in place of uniqueA and uniqueB respectively.

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

Sidebar

Related Questions

Say I have two arrays, items and removeItems and I wanted any values found
Let's say I have two arrays: int ArrayA[] = {5, 17, 150, 230, 285};
Let's ets say I have two arrays: $arr1 = array("a","b","c"); $arr2 = array("1","2","3"); function
Let's say I have two arrays: int[] array1 = new int[2000000]; int[] array2 =
I have two arrays, say A={1, 2, 3} and B={2, 4, 8} (array item
Let's say we have a two dimensional arrays, arr[N][N] , where N is a
Inspired by Raymond Chen's post , say you have a 4x4 two dimensional array,
I have a situation where I have two arrays and I use one array(A)
Say I have 3 arrays of arrays and when I write in any of
Let's say I have two classes that look like this: public class ByteFilter {

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.