How do i check each element of one array into another? here array2 contains each element of array1.
code:
function find(a, b) {
var ai=0, bi=0;
var result = [];
while( ai < a.length && bi < b.length )
{
if (a[ai] < b[bi] ){ ai++; }
else if (a[ai] > b[bi] ){ bi++; }
else /* they're equal */
{
result.push(a[ai]);
ai++;
bi++;
}
}
if(JSON.stringify(a)==JSON.stringify(result)){
return true;
}else if(JSON.stringify(b)==JSON.stringify(result)){
return true;
}else{
return false;
}
// return result;
}
var array1 = ["Area", "Code", "Date", "Invoice Amt", "Invoice No", "Party Address", "Party Name", "Pincode"];
var array2 = ["Area", "Code", "Date", "Invoice Amt", "Invoice No", "Name", "Party Address ", "Party Name", "Pincode"];
console.log(find(array1, array2)); //returns false
console.log(find(array2, array1)); // return false