Skip to content

Commit fc7924a

Browse files
committed
Merge pull request #1 from sverrejoh/master
Fixed issue with `undefined` values
2 parents 699f273 + 0e88763 commit fc7924a

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ module.exports = function shallowDiff(base, compared) {
5454
loop(compared, function (value, idx) {
5555

5656
// To get the added
57-
if (typeof base[idx] == "undefined") {
57+
if (!(idx in base)) {
5858
added.push(idx);
5959

6060
// The updated
@@ -72,7 +72,7 @@ module.exports = function shallowDiff(base, compared) {
7272
loop(base, function (value, idx) {
7373

7474
// To get the deleted
75-
if (typeof compared[idx] == "undefined") {
75+
if (!(idx in compared)) {
7676
deleted.push(idx);
7777
}
7878
});

test/shallow-diff.spec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ describe("shallow-diff", function () {
3434
expect(Array.isArray(result.deleted)).to.be.true;
3535
});
3636

37+
it("should should handle `undefined` values", function() {
38+
var result = sut({a: undefined}, {a: undefined});
39+
expect(result.added.length).to.equal(0);
40+
expect(result.deleted.length).to.equal(0);
41+
});
42+
3743
describe("with an array", function () {
3844
var initialArray = ["a", "b", "c", "d"],
3945
finalArray = ["a", "d", "e"];

0 commit comments

Comments
 (0)