Last active
January 27, 2023 12:19
-
-
Save Jacknq/82de1a0aa6111e91005654ee1b10b49d to your computer and use it in GitHub Desktop.
test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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