-5

When i console two arrays below is how it look

aa=  [0: "349",1: "810",2: "863",3: "657",4: "602",5: "317",6: "665",7: "865",8: "624",9: "805",10: "887",11: "659"];

bb=[0: "349", 1: ""];

cc=find_flight(aa,bb);

in both arrays 349 is matching, once match it should return 1. Below is how i tried

function find_flight(aa,bb)
    {
        if(a2.toString() == a1.toString())
        {
                return true;
        }
    }


console.log(aa+'-'+bb);

Output: 349,810,863,657,602,317,665,865,624,805,887,659-349,

Its not matching can any one give solution !!!!

sivashanker
  • 55
  • 2
  • 8

2 Answers2

1
function find_flight(a,b)
{
var check  = false;
a.forEach(function(x) { 
   b.forEach(function(y) { 
       //console.log(x+"  "+y +"   "+(x==y?1:0));
       if (x==y) { check=true; } 
   });
});
return check;
}

var aa= [1,2,3,4,5,6];
var bb= [0,9,8,7, 4];

Use it like

console.log(find_flight(aa,bb));
void
  • 36,090
  • 8
  • 62
  • 107
0

One approach would be this:

found=false; 
aa.forEach(function(e) { 
   bb.forEach(function(e2) { 
     if (e === e2) { found=true; } 
   });
});

I used this to initialize the arrays as my console did not accept your syntax.

aa = ["349","810","863","657","602","317","665","865","624","805","887","659"];
bb = ["349",""];
cmouse
  • 672
  • 1
  • 6
  • 22