# Function which checks overlapping numbers

Greeting all!

I am trying to write a function that takes two objects and checks if they have overlapping numbers. I have managed to see if they are overlapping, but not if they arent…if that makes sense.

``````function checkOverlap(lineA, lineB) {
var result = 0;
for(var a in lineA) {
for(var b in lineB) {
if(a.length > b.length) {
result = true ;
}
}
}
return result;
}
``````

If anyone has tips on how to make this better or how to check if they aren’t overlapping. let me know!

Can you show an example input? I’m not sure what this is supposed to do at the minute.

I am writing a function that checks for the same number in mulitple arrays. It seems to work when I have an array like `[] and [2,4,5]` however when I have a two arrays such as `[1,2,3,4] and [3,4,5]` it doesnt show that 3 and 4 are the matching numbers. Function below.

``````function intersection(listOne, listTwo) {
var matches = [];
for ( var i = 0; i < listOne.length; i++ ) {
for ( var e = 0; e < listTwo.length; e++ ) {
if ( a[i] === b[e] ) matches.push( a[i] );
}
}
return matches;
}
``````

Any assistance is appreciated.

I have merged your second topic with this one. Please do not create multiple topics for the same question.

my apologies for this. They do have some differences however it is possible I did not explain it correctly

`a` and `b` are not defined: you must use the parameter you’ve written, `listOne` and `listTwo` in your example^^
I’m wondering about how it could works in your code: probably you have defined some a, b variables globally and this led to the scope issue^^

Ah you are right, I did pass in the correct arguments, unfortunately it is still not working the way I would like

Mh, what’s the issue now? I mean, the second code you posted should work (if no items repeat itself): with work i mean that it find the numbers present in both the parameter arrays and return another array with the numbers founded^^
Let us know if we can do something more

1 Like