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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:36:31+00:00 2026-05-26T22:36:31+00:00

I am stuck in this. I got 2 arrays, I don’t know the length

  • 0

I am stuck in this. I got 2 arrays, I don’t know the length of each one, they can be the same length or no, I don’t know, but I need to create a new array with the numbers no common in just a (2, 10).

For this case:

    var a = [2,4,10];
    var b = [1,4];

    var newArray = [];

    if(a.length >= b.length ){
        for(var i =0; i < a.length; i++){
            for(var j =0; j < b.length; j++){
                if(a[i] !=b [j]){
                    newArray.push(b);        
                }        
            }
        }
    }else{}  

I don’t know why my code never reach the first condition and I don’t know what to do when b has more length than a.

  • 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-26T22:36:31+00:00Added an answer on May 26, 2026 at 10:36 pm

    It seems that you have a logic error in your code, if I am understanding your requirements correctly.

    This code will put all elements that are in a that are not in b, into newArray.

    var a = [2, 4, 10];
    var b = [1, 4];
    
    var newArray = [];
    
    for (var i = 0; i < a.length; i++) {
        // we want to know if a[i] is found in b
        var match = false; // we haven't found it yet
        for (var j = 0; j < b.length; j++) {
            if (a[i] == b[j]) {
                // we have found a[i] in b, so we can stop searching
                match = true;
                break;
            }
            // if we never find a[i] in b, the for loop will simply end,
            // and match will remain false
        }
        // add a[i] to newArray only if we didn't find a match.
        if (!match) {
            newArray.push(a[i]);
        }
    }
    

    To clarify, if

    a = [2, 4, 10];
    b = [4, 3, 11, 12];
    

    then newArray will be [2,10]

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

Sidebar

Related Questions

Hi i got stuck with this problem, i can't find out how to get
I got stuck in this problem for an hour. I am thinking this is
I got stuck with this problem. I wrap two tables inside of a h:form.
I'm stuck with this pretty silly thing; I got a textfile like this; Hello::140.0::Bye
Since my AS3 and Php/Java knowledge is not good I got stuck on this
I got stuck when chmod a file. At the bottom of this page ,about
I have been working on this for few hours and got stuck, so how
I'm stuck for 3 days on this. I got a Dicom files that i
Firslty, I'm aware of some similar questions along the lines of this one, but
I have recently created an upload function, but I don't know how to change

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.