Last active
September 9, 2020 23:42
-
-
Save ZhenDeng/f16822b66069bd0cc40e08c9614948d4 to your computer and use it in GitHub Desktop.
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
this.schoolYearArray = [...new Set(this.attendanceDetails.map(item => item.SchoolYear))]; |
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(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