Type of the objects to compare.
class Vector implements Comparable<Vector> {
constructor(private x: number, private y: number) {}
add(vector: Vector) : Vector {
return new Vector(this.x + vector.x, this.y + vectory.y)
}
get abs2() : number {
return this.x*this.x + this.y*this.y;
}
get abs() : number {
return Math.sqrt(this.x*this.x + this.y*this.y);
}
compareTo(vector: Vector) : number {
return this.abs2 - vector.abs2;
}
static get compare() : Comparator<Vector> {
return byProp("abs2")
}
}
[new Vector(2,3), new Vector(1,2)].sort(Vector.compare);
Generated using TypeDoc
An interface for comparable objects of the same type. They are compared via a special method 'compareTo'.
Type of the items that are compared.