function find(A, B) {
R = [-1, -1];
outer: for (var i = 0; i < A.length; i++) {
for (var j = 0; j < B.length; j++) {
if (A[i] == B[j]) {
R = [i, j];
break outer;
break;
}
}
}
return R;
}
(R[0] + 1) * (R[1] + 1) итераций.
function find(A, B) {
var C = {}, R = [-1, -1];
for (var i = A.length - 1; i >= 0; i--)
C[A[i]] = i;
for (var i = 0; i < B.length; i++) {
if (B[i] in C) {
R = [C[B[i]], i];
break;
}
}
return R;
}
A.length + R[1] - 1 итераций.