1
Vote

Linq Js Distinct Doesn't work

description

i'm developing an angularJs application, which has a history, the history get filled by user search, and then store in localStorage, the process is like this:
function queue(searchHistory) {
                var dataList = getData(); //from local storage

                //Add New Data
                dataList.unshift(searchHistory);

                //Remove Repeated Data
                var dataList = Enumerable.From(dataList)
                    .Distinct("$._sourceAirport._iataCode + '-' + $._destinationAirport._iataCode + $.startDate + '-' + $.endDate")
                    .ToArray();

                //Decrease Queue Size To Its Max
                while(dataList.length>maxQueueSize){
                    dataList.pop();
                }

                setData(dataList); //to local storage
}
what happen here, is the last item which come from function parameter won't confilict with repeated item inside the list.

you can see in watch that the first (new item) and last item (exists item) after running distinct are repeated...

file attachments

comments

deadManN wrote Jan 12, 2016 at 8:44 AM

The Issue came from my side,
The first Object i generated by js and contains getter and setter, while the others doesn't have this, since i cant serialize it into the the string...

so this part, $.startDate + '-' + $.endDate" is defined for first, and "undefined" for other, make first item look different.

i had to trace the code deep into your codes, and i saw that which i didn't expect, i though i may failed becasue of encoding change after reading back from localStorage, not that one...

Hopes:
if there was a way to do something like this:

.Distinct(function(data){data.x+data.y})

it was both traceable and understandable,... can you do that?