Skip to content

Commit

Permalink
Add support for objects in default comparator
Browse files Browse the repository at this point in the history
  • Loading branch information
janogonzalez committed Feb 23, 2015
1 parent d3d1154 commit 678a9af
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function PriorityQueue(comparator) {
* @api public
*/
PriorityQueue.DEFAULT_COMPARATOR = function(a, b) {
if (a instanceof Number && b instanceof Number) {
if (typeof a === 'number' && typeof b === 'number') {
return a - b;
} else {
a = a.toString();
Expand Down
7 changes: 7 additions & 0 deletions test/priorityqueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ describe('PriorityQueue()', function() {
it('returns a positive number when a > b', function() {
expect(PriorityQueue.DEFAULT_COMPARATOR(10, 1)).to.be.above(0);
});

it('works with `Number` objects', function() {
var a = Number(10)
var b = Number(1000)

expect(PriorityQueue.DEFAULT_COMPARATOR(a, b)).to.be.below(0);
});
});
});

Expand Down

0 comments on commit 678a9af

Please sign in to comment.