This project has moved. For the latest updates, please go here.
2
Vote

Distinct function not working properly with an object

description

I made a fix!
We assume that if the programmer doesn't want a distinct on a base type collection he just uses a clause to help knowing how to compare them.
Enjoy

Distinct: function (clause) {
        var item;
        var dict = new Object();
        var retVal = new Array();
        for (var i = 0; i < this.items.length; i++) {
            item = this.items[i];
            if ((clause == null && dict[item] == null) || (clause != null && dict[clause(item)] == null)) {
                if (clause == null)
                    dict[item] = true;
                else
                    dict[clause(item)] = true;
                retVal[retVal.length] = item;
            }
        }
        dict = null;
        return new JSLINQ(retVal);
    },

comments