Skip to main content

interface Comp<K>

An object providing methods to compare two values of type K.

Companion namespace: Comp

Type parameters

NameDescription
Kthe value type

Methods

compare

Returns 0 if given value1 and value2 are equal, a positive value is value1 is greater than value2, and a negative value otherwise.

Definition

compare(value1: K, value2: K): number;

Parameters

NameTypeDescription
value1Kthe first value to compare
value2Kthe seconds value to compare
example
const c = Comp.numberComp()
console.log(c.compare(5, 5))
// => 0
console.log(c.compare(3, 5))
// => -2
console.log(c.compare(5, 3))
// => 2

isComparable

Returns true if this instance can compare given obj.

Definition

isComparable(obj: any): obj is K;

Parameters

NameTypeDescription
objanythe object to check
example
const c = Comp.numberComp()
console.log(c.isComparable(5))
// => true
console.log(c.isComparable('a'))
// => false