Javascript Array except(arr, comparer)

Description

Javascript Array except(arr, comparer)


Array.prototype.except = function (arr, comparer) {
    if (!(arr instanceof Array)) arr = [arr];
    comparer = comparer || EqualityComparer;
    var l = this.length;
    var res = [];
    for (var i = 0; i < l; i++) {
        var k = arr.length;
        var t = false;
        while (k-- > 0) {
            if (comparer(this[i], arr[k]) === true) {
                t = true;/*from   w ww. j av  a2 s  . c o m*/
                break;
            }
        }
        if (!t) res.push(this[i]);
    }
    return res;
};



PreviousNext

Related