// Target is array that has all elements
// Arr is the array to be check to see if it contains all elements
// every returns true if every value of the array matches the condition
let array1 = [1,2,3],
array2 = [1,2,3,4],
array3 = [1,2];
let checker = (arr, target) => target.every(v => arr.includes(v));
console.log(checker(array2, array1)); // true
console.log(checker(array3, array1)); // false
https://stackoverflow.com/questions/53606337/check-if-array-contains-all-elements-of-another-array
No comments:
Post a Comment