xxxxxxxxxx
let arr1 = [4,5,6];
let arr2 = [2,3,4,5,6,7,8];
compute = (a,b) =>
a.filter((x) => !b.includes(x)).length === 0 ||
b.filter((x) => !a.includes(x)).length === 0
// One range fully contain the other?
console.log(compute(arr1,arr2)) //true
xxxxxxxxxx
// how to check all elements in array includes in another array javascript
const includesAll = (arr, values) => values.every(v => arr.includes(v));
includesAll([1, 2, 3, 4], [1, 4]); // true
includesAll([1, 2, 3, 4], [1, 5]); // false
xxxxxxxxxx
var arr1 = [
{
"prop1": "value1",
"prop2": "value2",
},
{
"prop1": "value3",
"prop2": "value4",
},
{
"prop1": "value5",
"prop2": "value6",
},
];
var arr2 = ['value1','value3', 'newValue'];
// finds all the elements of arr2 that are not in arr1
arr2.filter(
val => !arr1.find( arr1Obj => arr1Obj.prop1 === val)
); // outputs "newValue"