我有两个数组,希望部分匹配它们(即第一个数组的某些元素应该出现在第二个数组中,但不是全部).我有一个解决方案,但我觉得我可以使用一个更有效的.以下是用例:
const array_1 = [ 7, 6 ];
const array_2 = [ 4, 6 ,7, 2, 9 ];
const isSomeItemMatched = array_1.some( item => array_2.includes(item) );
const isAllItemMatched = array_1.every( item => array_2.includes(item) );
const isPartiallyMatched = !isAllItemMatched && isSomeItemMatched;
请让我知道,如果有一个优化的方式做这件事.