Skip to content

Cleaner diffs for inserted array items #38

@lukechilds

Description

@lukechilds

Isolated test case as requested in avajs/ava#1521

If you append an item to an array and diff:

var concordance = require('concordance');
const orig = [
  'foo',
  'bar',
  'fizz',
  'buzz'
];
const copy = Array.from(orig);
copy.push('hi')
concordance.diff(orig, copy);

You get neat output:

  [
    'foo',
    'bar',
    'fizz',
    'buzz',
+   'hi',
  ]

However if you insert anywhere else and diff:

var concordance = require('concordance');
const orig = [
    'foo',
    'bar',
    'fizz',
    'buzz'
];
const copy = Array.from(orig);
copy.unshift('hi')
concordance.diff(orig, copy);

The output is quite hard to follow after the inserted item:

  [
-   'foo',
+   'hi',
-   'bar',
+   'foo',
-   'fizz',
+   'bar',
-   'buzz',
+   'fizz',
+   'buzz',
  ]

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions