Count elements and return new array

Feb 10, 2015 at 10:31 AM
Edited Feb 10, 2015 at 12:56 PM
Hello,

Let's assume I have a list of objects, where each object has these properties: Name, Date, Age;.
What I would like to achieve is create a new array of objects with Name and Count. where Name is the same as in the first list, and Count is the number of how many objects with given Name is in the first List. For example:
Main list:
{Asd, 02-02-2012, 1},
{Asd, 02-02-2012, 1},
{Asd1, 02-02-2012, 1},
{Asd2, 02-02-2012, 1},
{Asd2, 02-02-2012, 1}
Result list:
{Asd, 2}
{Asd1, 1}
{Asd2, 2}
How can I achieve that?

I don't how to delete thie thread but I solved the problem with this:
//here is $http.get function, returning "data"
var countArray = JSLINQ(data).Distinct(function(item) { return item.project; });
        for (var i = 0; i < countArray.Count(); i++) {
            var count = JSLINQ(data).Count(function (item) { return item.project == countArray.items[i]; });
            dataForChart.push([countArray.items[i], count]);
        }