Copy codeThe Code is as follows:
I used my own articles in previous projects. There should be no bugs. If you have any better ideas, please kindly advise,
Var Return_AddStrFn = function (oldArr, newArr ){
Var t = this;
// Deduplication Method
Array. prototype. unique4 = function (){
// This = arr;
Var temp = new Array ();
This. sort ();
For (I = 0; I <this. length; I ++ ){
If (this [I] = this [I + 1]) {
Continue;
}
Temp [temp. length] = this [I];
}
Return temp;
}
Var a = d = oldArr. unique4 (); // old Array
Var B = 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 (a [I]);
I ++;
} Else if (B [j] <a [I]) {
C. push (B [j]);
J ++;
} Else {
I ++;
J ++;
}
}
While (I <a. length ){
C. push (a [I]);
I ++;
}
While (j <B. length ){
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; // the newly added
// For (var I = 0; I <c. length; I ++ ){
// For (var j = 0; j <d. length; j ++ ){
// If (d [j] = c [I]) {
// Dels. push (d [j]);
//}
//}
//}
// Alert ("dels:" + dels); // Delete
}
Call method: var arr = [1, 2, 2, 3, 3, 4, 5];
Var arr2 = [1, 2, 5]
Var addStr = Return_AddStrFn (arr2, arr );