public
Last active

  • Download Gist
sample.jsnext.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
trait ComparableTrait {
requires lessThan;
requires equals;
 
function lessThanOrEquals(other) {
return this.lessThan(other) || this.equals(other);
}
function greaterThan(other) {
return other.lessThan(this);
}
function greaterThanOrEquals(other) {
return other.lessThan(this) || this.equals(other);
}
function notEquals(other) {
return !(this.equals(other));
}
}
 
class Interval {
mixin ComparableTrait;
 
new(min, max) {
this.start = min;
this.end = max;
this.size = max - min - 1;
}
function lessThan(ival) {
return this.end <= ival.start;
}
function equals(ival) {
return this.start == ival.start && this.end == ival.end;
}
}
 
var i1 = new Interval(0, 5);
var i2 = new Interval(7, 12);
alert(i1 + ' == ' + i2 + ': ' + i1.notEquals(i2)); // true
alert(i1 + ' < ' + i2 + ': ' + i1.greaterThan(i2)); // false

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.