Skip to content

Instantly share code, notes, and snippets.

@Woodsphreaker
Created March 13, 2018 19:19

Revisions

  1. Woodsphreaker created this gist Mar 13, 2018.
    15 changes: 15 additions & 0 deletions compareElements.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    const arr1 = [{id: 5, msg: 'hshh'}, {id: 56, msg: 'hshgdh'}, {id: 7, msg: 'hshh'}]

    const arr2 = [{id: 5, msg: 'hshh'}, {id: 6, msg: 'hshgdh'}, {id: 7, msg: 'hshh'}]

    const compare = (list1, list2) => {

    const map = new Map()
    for (let {id, msg} of list1) {
    map.set(id, msg)
    }

    return list2.filter(({id, msg}) => !map.has(id))
    }

    compare(arr1, arr2)