Created
November 14, 2011 14:19
-
-
Save iRyusa/1364034 to your computer and use it in GitHub Desktop.
Check if one tab contain the other
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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