Guest User

Untitled

a guest
Nov 24th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. groupBy(array: any[], property: string) {
  2. return array.reduce((prev, next) => {
  3. // If the group doesn't exist, create it
  4. if(!prev[property]) { prev[property] = [next]; }
  5. // Else, we push it in
  6. else { prev[property].push(next); }
  7. // Mandatory return
  8. return prev;
  9. }, {});
  10. }
  11. public getpeople(people:Person[]):Person[]
  12. {
  13. return groupby(people.filter((person: Person) => person.age>30 && person.age<40), "gender");
  14. }
Add Comment
Please, Sign In to add comment