TL DR; What is the most efficient way to sort and compare values in a multiple arrays?
Okay, so we'll assume a few constants to make this whole thing simple var a = [1, 2, 3, 4, 5, 6], b = [0, 9, 8, 7, 6, 88, 99, 77], i, j;
Now if I wanted to see if any value in a is equal to any other value in b I'd have to sort through one of these arrays 6 times. That's a lot of work, and it would seem there should be a more efficient way to do this. For those needing a visual aide here you are ( and yes I know about -- and ++ I just don't like to use 'em ):
for (i = a.length - 1; i > -1; i -= 1) {
for (j = b.length - 1; j > -1; j -= 1) {
if (a[i] === b[j]) {
return b[j];
}
}
}
The B array gets ran through once for EACH element in A. Again, certainly there is a more efficient way to complete this task?
-Akidi