function arrConcat (arrA, arrB) {
const res = [],
dir = {};
let pointerA = 0,
pointerB = 0;
while (pointerA < arrA.length && pointerB < arrB.length) {
let temp;
//将较小的值推到栈中
if (arrA[pointerA] > arrB[pointerB]) {
temp = arrB[pointerB++];
}
else {
temp = arrA[pointerA++];
}
//字典记录添加过的数据
if (!dir.hasOwnProperty(temp)) {
res.push(temp);
dir[temp] = true;
}
}
//没有遍历到尾部的数组
const otherData = arrA.slice(pointerA).concat(arrB.slice(pointerB));
res.push(...otherData);
console.log(res);//[1,2,4,5,6]
}
arrConcat([1,2,4,5],[2,4,6])