comparelist

1.0.5 • Public • Published

comparelist

比较数组前后的变化,新增或删除了哪些 Compare two array for 'remove list' 'add list' and same key.

how to use

step 1

step 2

import comparelist from 'comparelist';

  • use 1
var arr1 = [ 1, 2, 3, 4 ];
var arr2 = [ 3, 4, 5, 6 ];

var result = comparelist({
    listBefore: arr1, 
    listNow: arr2, 
    // key, no use for this
});

console.log(result);
{ 
    removeList: [ 1, 2 ], 
    addList: [ 5, 6 ], 
    sameKey: [ 3, 4 ] 
}

- use 2

var arr1 = [ 
    { id: 1, ... }, 
    { id: 2, ... }, 
    { id: 3, ... }, 
    { id: 4, ... } 
];
var arr2 = [ 
    { id: 3, ... }, 
    { id: 4, ... }, 
    { id: 5, ... }, 
    { id: 6, ... } 
];

var result = comparelist({
    listBefore: arr1, 
    listNow: arr2, 
    key: 'id',
});

console.log(result);
{ 
    removeList: [ 
    { id: 1, ... }, 
    { id: 2, ... } ], 
    addList: [ 
        { id: 5, ... }, 
        { id: 6, ... } 
    ], 
    sameKey: [ 3, 4 ] 
}

解决重复劳动力是一件很有意义的事情,
有什么好的想法,欢迎一起成长交流
WeChat:mrliaojun

github

Jared

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i comparelist

      Weekly Downloads

      6

      Version

      1.0.5

      License

      ISC

      Unpacked Size

      7.4 kB

      Total Files

      4

      Last publish

      Collaborators

      • aisriver