Skip to content

Instantly share code, notes, and snippets.

@Jacknq
Last active January 27, 2023 12:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jacknq/82de1a0aa6111e91005654ee1b10b49d to your computer and use it in GitHub Desktop.
Save Jacknq/82de1a0aa6111e91005654ee1b10b49d to your computer and use it in GitHub Desktop.
test.ts
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");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment