{"ScriptPreparationCode":"var arr = [{\r\n item: {\r\n id: 1,\r\n name: \u0022Abc\u0022\r\n },\r\n amount: 1\r\n}, {\r\n item: {\r\n id: 1,\r\n name: \u0022Abc\u0022\r\n },\r\n amount: 2\r\n}, {\r\n item: {\r\n id: 2,\r\n name: \u0022Abc\u0022\r\n },\r\n amount: 2\r\n},{\r\n item: {\r\n id: 1,\r\n name: \u0022Abc\u0022\r\n },\r\n amount: 2\r\n}];","TestCases":[{"Name":"forEach","Code":"let merged = {}\r\n\r\narr.forEach( element =\u003E {\r\n if (merged[element.item.id]) {\r\n merged[element.item.id].amount \u002B= element.amount\r\n } else {\r\n merged[element.item.id] = element\r\n }\r\n})","IsDeferred":false},{"Name":"Reduce","Code":"Object.values(arr.reduce((a,curr)=\u003E{\r\n if(!a[curr.item.id])\r\n a[curr.item.id] = curr;\r\n else \r\n a[curr.item.id].amount \u002B= curr.amount;\r\n return a;\r\n},{}));","IsDeferred":false}]}