Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- groupBy(array: any[], property: string) {
- return array.reduce((prev, next) => {
- // If the group doesn't exist, create it
- if(!prev[property]) { prev[property] = [next]; }
- // Else, we push it in
- else { prev[property].push(next); }
- // Mandatory return
- return prev;
- }, {});
- }
- public getpeople(people:Person[]):Person[]
- {
- return groupby(people.filter((person: Person) => person.age>30 && person.age<40), "gender");
- }
Add Comment
Please, Sign In to add comment