Search javascript hashmap with another hashmap value -


i have 2 hashmaps, hashmap1 , hashmap2. each hashmap has multiple keys multiple values each key.

var hashmap1 = {     a:[          'aaa',          'bbb'                ]     b:[         'ccc',         'ddd'     ] };  var hashmap2 = {     a:[          'aaa',          'bbb',          'ccc',     ]     b:[         'ddd',         'eee',         'fff'     ] }; 

in above example, want check if of values each key within hashmap1 exist within values of hashmap2.

so in above example values within hashmap1 present within values of hashmap2. if case maybe mark variable true else mark false.

thanks help

i wrote similar compare function. uses jquery, hope not problem.

/**  * checks if object or array subset of object or array.  * works scalar types.  *  * @requires jquery  * @param {mixed} partial  * @param {mixed} whole  * @param {boolean} strict_arrays in arrays, compare a[i] === b[i] instead of inarray(a[i], b). default false.  * @returns {boolean} 'partial' subset of 'whole'  */ function is_subset(partial, whole, strict_arrays) {     if (partial instanceof array) {         if (!(whole instanceof array)) return false;         var matches = true;         $.each(partial, function(i, value){             if ((!strict_arrays && $.inarray(value, whole) < 0) || (strict_arrays && value !== whole[i])) {                 matches = false;                 return false;             }         });         return matches;     } else if (typeof partial === 'object' && partial !== null) {         if (!(typeof whole === 'object')) return false;         var matches = true;         $.each(partial, function(prop, value) {             if (!is_subset(value, whole[prop])) {                 matches = false;                 return false;             }         });         return matches;     } else {         return partial === whole;     } } 

usage example: is_subset(hashmap1, hashmap2)


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -