I am using linq.js "//cdnjs.cloudflare.com/ajax/libs/linq.js/2.2.0.2/linq.min.js"
The objective is to get "sum" of a field using group by clause. The code is working fine but "quantity" is considered as a string and appending numbers. If I use g.Sum(parseInt("$.quantity")) or parseFloat I am getting error b is not a function. What am I missing?
If I want set some initial value to quantity, how can I?
aggregatedData = Enumerable.From(someData)
.GroupBy("$.id", null,
function (key, g) {
return {
stock: key,
quantity: g.Sum("$.quantity"),
avgprice: g.Average("$.average_price")
}
})
.ToArray();
I figured it out. g.Sum(function (s) { return parseFloat(s.quantity | 0); })