andreyvit/json-diff — pull request #8 by unconed (2014-01-30 10:46:29+00:00)
Title: Fix colliding fuzzy matches

Diffing the following two arrays shows "c" incorrectly being added to the first object.

a.json:

[
{ "name": "Foo", "a": 3, "b": 1 }
]

b.json

[
{ "name": "Foo", "a": 3, "b": 1 },
{ "name": "Foo", "a": 3, "b": 1, "c": 1 }
]

In `scalarize`, it maps a target array's objects to matching source objects, but it doesn't check whether the mapping exists already.

```
else if fuzzyOriginals && (bestMatch = findMatchingObject(item, index, fuzzyOriginals)) && bestMatch.score > 40
originals[bestMatch.key] = item;
```

The proposed change passes all existing mappings into findMatchingObject and does the check there so that an alternate match can be found.