Skip to content

Instantly share code, notes, and snippets.

@yorkie
Created November 14, 2013 08:42
Show Gist options
  • Save yorkie/7463471 to your computer and use it in GitHub Desktop.
Save yorkie/7463471 to your computer and use it in GitHub Desktop.
check the same elements from 2 arrays.
// check the same elements from 2 arrays.
function compare(a, b){
var set = [];
var i = 0, j = 0;
var jHit = -1;
while (i < a.length && j < b.length) {
if (a[i]==b[j]){
set.push(a[i]);
i = i+1;
jHit = j;
}
j = j+1;
if (j == b.length) {
i=i+1;
j=jHit+1;
}
}
return set;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment