Convert strConflictedYesReviewers data into a single object which is group by ownerid and make array of opportunityid
I get a dynamic string(strConflictedYesReviewers) which contains multiple user recordswhere each record is separated by semicolon and then each record represents ownerid and opportunityid separated by asterisk. I have done it but looking for a better approach or code review.
const strConflictedYesReviewers = "88639280*198719943;88642547*198721749;88627345*198721749;88664734*198721749;88686221*198721749;88676217*198721749;88664734*198721749;88686221*198721749;88676217*198721749;"
.split(";")
.map(item => item.split("*"))
.filter(item => !!item[0])
.map(item => ({ownerid: item[0], opportunityid: item[1]}))
.reduce(function(acc, curr) {
(acc[curr["ownerid"]] = acc[curr["ownerid"]] || []).push(curr["opportunityid"]);
return acc;
}, {});
console.log(strConflictedYesReviewers);
Comments
Post a Comment