In angular JS, I have a variable that keeps track of people and their age
$scope.people = [
{
name: "Lucy",
age: "18"
}, {
name: "Michael",
age: "24"
}, {
name: "Lisa",
age: "46"
}
];
The user can add more people via a simple form:
<input ng-model="newPerson.name">
<input ng-model="newPerson.age">
<button ng-click="addNewPerson()">Add</button>
At the bottom of the page, I want a simple pie graph showing the population by age group eg.(>18, 18-25, 26-35, 36-45, 45<). To do that, I need to be able to filter the $scope.people by age, get the number of each group.
I know I could use normal javascript to loop through the whole array, get a count of each age group. And whenever a new person is added, just increment the count in that particular group, but I was wondering if there is a more efficient and angular-esque way to do this?