I'm trying convert one method to generic method to use with arrow function in JavaScript, but somehow not able to figure how should I convert it.
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()
)};
Predicate which I'm receiving in this method is like ƒ (x) { return x.status; }
.
I want to replace this e.status
to with some generic so I can use it like arrayData.groupBy(x=>x.status)
.
As a beginner, I'm not able to figure out how I should do this.
I found method in a post @ https://stackoverflow.com/a/47752730/5001462, posted by @Arthur Tacca
Thanks in advance