diff-sorted-array

3.0.0 • Public • Published

Build Status Coverage

diff-sorted-array

Diff two sorted array for best performance.

Install

$ npm i diff-sorted-array

Usage

const {diff, justDiff, asc, desc} = require('diff-sorted-array')

diff(a, b)

  • a Array
  • b Array
const a = [2, 3, 1]
const b = [3, 4, 2]

const result = diff(a, b, sorter)

result.unchanged
// [2, 3]

result.added
// [4]

result.deleted
// [1]

justDiff(a, b, sorter)

  • sorter Function(a: any, b: any): number the compareFunction of Array.prototype.sort(compareFunction)

Sometimes we want to do the sorting ourself, so that we can manage the process to increase performance.

justDiff only accepts two arrays that both have already been sorted to speed up the matching.

const sorter = (a, b) => a > b
  ? 1
  : - 1

const a = [2, 3, 1]
const b = [3, 4, 2]

a.sort(sorter)
b.sort(sorter)

justDiff(a, b, sorter)
// The same result as above

asc and desc

Built-in sorter to sort arrays in ascending or descending order.

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i diff-sorted-array

Weekly Downloads

103

Version

3.0.0

License

MIT

Unpacked Size

5.11 kB

Total Files

5

Last publish

Collaborators

  • kael