remove redundance in compare-functions I wrote some compare-functions that I pass to other methods in javascript:

function equal(a, b) {
    if (a instanceof Date) return a.getTime() == b.getTime();
    return a == b;
}

function lessThan(a, b) {
    if (a instanceof Date) return a.getTime() &lt; b.getTime();
    return a &lt; b;
}

function greaterThan(a, b) {
    if (a instanceof Date) return a.getTime() &gt; b.getTime();
    return a &gt; b;
}

function lessOrEqual(a, b) {
    return equal(a, b) || lessThan(a, b);
}

function greaterOrEqual(a, b) {
    return equal(a, b) || greaterThan(a, b);
}


Is there a way to get this a bit more compact? If I want to add another comparable type I always have to modify the first three functions.
No need to check if the variables are instanceof Date. A dates value is its time so when you make (less than/greater than) comparisons with a Date instance (x) you're essentially comparing it to +x or x.valueOf() which will be the same as x.getTime(). Therefore the below will always be equivalent:

function equal(a, b) {
    if (a instanceof Date &amp;&amp; b instanceof Date) return +a == +b; //compare the 2 dates times as noted in the above statement +x == x.getTime() == x.valueOf()
    return a == b;
}

function lessThan(a, b) {
    return a &lt; b;
}

function greaterThan(a, b) {
    return a &gt; b;
}