JS一个数组的值匹配另一个数组


let all = ['a', 'b', 'c', 'd', 'e'];

let bb = ['a', 'b']; //返回ture

let cc = ['b', 'f'];//返回ture

let dd = ['y', 'x'];//返回false

let ee = ['x'];//返回false

let ff = ['q', 'w','t', 'x'];//返回false

现有这两个数据,

如果bb中的某一项在aa中存在,返回 ture ,否则false。

function matchArray(arr1, arr2) {
  return arr2.some(item => arr1.includes(item));
}

let all = ['a', 'b', 'c', 'd', 'e'];

console.log(matchArray(all, ['a', 'b'])); // true
console.log(matchArray(all, ['b', 'f'])); // true
console.log(matchArray(all, ['y', 'x'])); // false
console.log(matchArray(all, ['x'])); // false
console.log(matchArray(all, ['q', 'w','t', 'x'])); // false