each-diff

v1.1.2
Run on each unique object of a lists and fetch the same object from the other lists and give you them to you, for you to be able to compare between them. if the object will not exist on some list you get an undefined on he's place.
each diff each-diff diff-each

eachDiff

Run on each unique object of the lists and bring the same object from the other lists and give them to you, so you can be able to compare them. If the object does not exist in some list you get an undefined in is place.

Usage: eachDiff<T>(lists: Array<Array<T>>, callback: (items: Array<T>, indexes: Array<number>, lists) => void, detectBy?: keyof T): lists

import { eachDiff } from 'each-diff'

const
  listVersionA = [
    {
      name: `Sharon`,
      stars: 100
    },
    {
      name: `Adrien`,
      stars: 100
    }
  ],
  listVersionB = [
    {
      name: `Skye`,
      stars: 100
    },
    {
      name: `Adrien`,
      stars: 150
    }
  ]

eachDiff(
  [listVersionA, listVersionB], // It can be any length of lists
  ([obVersionA, obVersionB]) => {
    if (obVersionA === undefined) console.log(`${obVersionB.name} is newer`)
    else if (obVersionB === undefined) console.log(`${obVersionA.name} deleted`)
    else if (obVersionB.stars > obVersionA.stars) console.log(`${obVersionA.name} have now ${obVersionB.stars} stars instad of ${obVersionA.stars}`)
  },
  `name` // unique unchangeable property to determain that it is the same object in another version
)
// Output:  "Skye is newer" and "Sharon deleted" and "Adrien have now 150 stars instad of 100"

This module exported from utilizes project.

Metadata

  • MIT
  • Whatever
  • Natan Farkash
  • released 1/15/2019

Downloads

Maintainers