常用对数组的操作
从一个较大数组中剔除较小数组中内容
废话不多说 直接上代码:
public static excloudeSame(largeArr: Array<any>, smallArr: Array<any>): Array<any> {
for (let i = largeArr.length - 1; i >= 0; i--) {
let a = largeArr[i];
for (let j = smallArr.length - 1; j >= 0; j--) {
let b = smallArr[j];
if (a == b) {
largeArr.splice(i, 1);
smallArr.splice(j, 1);
break;
}
}
}
return largeArr;
}
没错,就是这么简单;
网友评论