Skip to content
This repository has been archived by the owner on Dec 18, 2020. It is now read-only.

Commit

Permalink
Added compare(other) method
Browse files Browse the repository at this point in the history
  • Loading branch information
Doug Judd committed Mar 31, 2015
1 parent 71b8af6 commit 2014c01
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Int64.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,21 @@ Int64.prototype = {
this.buffer.copy(targetBuffer, targetOffset || 0, this.offset, this.offset + 8);
},

/**
* Returns a number indicating whether this comes before or after or is the
* same as the other in sort order.
*
* @param {Int64} other Other Int64 to compare.
*/
compare: function(other) {
for (var i = 0; i < 8; i++) {
if (this.buffer[this.offset+i] !== other.buffer[other.offset+i]) {
return this.buffer[this.offset+i] - other.buffer[other.offset+i];
}
}
return 0;
},

/**
* Pretty output in console.log
*/
Expand Down

0 comments on commit 2014c01

Please sign in to comment.