Skip to content

Commit

Permalink
fixed map when using number indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
matej21 committed Nov 11, 2014
1 parent 7a911e3 commit 1a24d63
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function Map() {
key = this._key++;
} else {
var number = parseInt(key * 1);
if (!isNaN(number) && number > this._key) {
if (!isNaN(number) && number >= this._key) {
this._key = number + 1;
}
}
Expand Down
7 changes: 7 additions & 0 deletions test/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,11 @@ suite('Map', function () {
mapInst.set("foo", nested);
assert.deepEqual({foo: {bar: 1}}, mapInst.toObject(true));
});

test('number index', function () {
var mapInst = new Map();
mapInst.set(0, "a");
mapInst.set(null, "b");
assert.deepEqual({0: "a", 1: "b"}, mapInst.toObject());
});
});

0 comments on commit 1a24d63

Please sign in to comment.