Skip to content

Instantly share code, notes, and snippets.

@iRyusa
Created November 14, 2011 14:19
Show Gist options
  • Save iRyusa/1364034 to your computer and use it in GitHub Desktop.
Save iRyusa/1364034 to your computer and use it in GitHub Desktop.
Check if one tab contain the other
// Test tab
var tab1 = [1, 2, 3, 4, 5 ];
var tab2 = [1, 2, 3, 4 ];
// Hash to compare
var compare = {};
var found = true;
// Clone the tab
for ( var i in tab1 ) {
compare[tab1[i]] = tab1[i];
}
// use "in" operator to know if all element of tab2 are in tab1
for ( var i in tab2 ) {
if ( ! ( tab2[i] in compare ) ) {
found = false;
break;
}
}
// found == true tab1 contain all tab2 elements
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment