Algorithm to get changes between two arrays

后端 未结 8 1380
难免孤独
难免孤独 2021-02-04 05:43

I needed to create an algorithm which will (efficiently) take an old array and a new array and give me back the changes between the two (which items added, which removed). It ha

8条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-04 06:09

    // I prefer to not sort the arrays
    
    Array.prototype.diff= function(ar){
        var a= [], i= 0, L= this.length,
        ar= ar.concat(), t1, t2;
        while(i

提交回复
热议问题