I'm attempting to transform a method into a generic method for use with arrow functions in JavaScript, but I'm struggling to determine the correct way to do so.
groupBy: <Map>(predicate: (item: T) => Map[]) => Map[];
Array.prototype.groupBy = function (predicate) {
return this.reduce(
(entryMap, e) => entryMap.set(e.status, [...entryMap.get(e.status) || [], e]),
new Map()
)};
The predicate I am receiving in this method looks like ƒ (x) { return x.status; }
.
I would like to replace e.status
with something more generic so that I can use it like
arrayData.groupBy(x=>x.status)
.
As a beginner, I am unsure of how to proceed.
I came across a method in a post @ , shared by @Arthur Tacca
Thank you in advance