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!
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;
}
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^^
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