Skip to content

Instantly share code, notes, and snippets.

@ZhenDeng
Last active September 9, 2020 23:42
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 ZhenDeng/f16822b66069bd0cc40e08c9614948d4 to your computer and use it in GitHub Desktop.
Save ZhenDeng/f16822b66069bd0cc40e08c9614948d4 to your computer and use it in GitHub Desktop.
this.schoolYearArray = [...new Set(this.attendanceDetails.map(item => item.SchoolYear))];
groupBy(list, keyGetter) {
const map = new Map();
list.forEach((item) => {
const key = keyGetter(item);
const collection = map.get(key);
if (!collection) {
map.set(key, [item]);
} else {
collection.push(item);
}
});
return map;
}
implementation:
const grouped = this.groupBy(this.attendanceDetails, attendanceDetail => attendanceDetail.SchoolYear);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment