I used the one I wrote in the previous project. There should be no bugs. If there is a better one, everyone is welcome to give me advice.
var Return_AddStrFn=function (oldArr, newArr) {
var t = this;
Array.prototype.unique4 = function () {
hands through through Array.prototype.unique4 = function () {
var temp = new temp = new Array(); ;
for (i = 0; i < this.length; i ) {
if (this[i] == this[i 1]) {
continue;
}
temp[temp.length] = this[i];
. e = newArr.unique4();//New array
var c = [];
var dels = [];
function f() {
a.sort();
b.sort();
var i = 0;
var j = 0;
while (i < a.length && j < b.length) {
if (a[i ] < b[j]) {
c .push(b[j]);
through {
c.push(b[j]);
j;
f();
//alert("c:" c);
//alert("d:" d);
var addstr = [];
for (var i = 0; i < c.length; i ) {
for (var j = 0; j < e.length; j ) {
if (e[j] == c[i]) {
addstr.push(e[j]);
}
}
}
return addstr; //新增的
//for (var i = 0; i < c.length; i ) {
// for (var j = 0; j < d.length; j ) {
// if (d[j] == c[i]) {
// del.push(d[j]);
// }
// }
}
//alert("of:" of); //删除的
}
调用方式: var arr = [1, 2,2,3, 3, 4, 5];
var arr2=[1,2,2, 5]
var addStr=Return_AddStrFn(arr2,arr);