TypeScript Array数组 生成两个数组的交集,并且在数组中进行删除操作
/** * @method cutArr 删除数组1中,与数组2重复的数据 * Arr([1, 2, 3, 5], [2, 3, 4]) => [1, 5] * @param arr1 * @param arr2 * @returns {Array} */ const Arr = (arr1, arr2) => { function arrayDifference(a, b) { // 差集 a - b let clone = a.slice(0); // clone = a for (let i = 0; i < b.length; i++) { let temp = b[i]; for (var j = 0; j < clone.length; j++) { if (temp === clone[j]) { clone.splice(j, 1); // remove clone[j] } } } return clone; } function filterData(array) { // 去重 return Array.from(new Set(array)); } return filterData(arrayDifference(arr1, arr2)); } 标签:TypeScript,return,clone,let,数组,Array From: https://www.cnblogs.com/congcongerhuo/p/16725915.html