Home > Web Front-end > JS Tutorial > body text

JS code to compare the value of adding and deleting the old and new arrays_javascript skills

WBOY
Release: 2016-05-16 17:18:15
Original
1306 people have browsed it

Copy code The code is as follows:

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);

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!