JSFiddle - React, Tailwind, and code Playground
JavaScript
var arr1 = [{
name: 'one',
psno: '34'
}, {
name: 'two',
psno: '32'
}, {
name: 'three',
psno: '35'
}];
var arr2 = [{
name: 'one',
psno: '34'
}, {
name: 'two',
psno: '33'
}];
function hash(obj) {
return Object.keys(obj).reduce(function(p, c) {
return p.concat([c, obj[c]].join('|'));
}, []).sort().join('|');
}
function hashObject(obj) {
return hash(obj);
}
function within(arr) {
return function (el) {
return arr.indexOf(el) > -1;
}
}
function check(arr1, arr2) {
if (arr1.length < arr2.length) return false;
var hashedArr1 = arr1.map(hashObject);
return arr2.map(hashObject).every(within(hashedArr1));
}
var issubset= check(arr1, arr2);
console.log(issubset)