{"ScriptPreparationCode":null,"TestCases":[{"Name":"mina","Code":"const responseToTimeseries = (response) =\u003E {\r\n const entries = response.map(({ data }) =\u003E Object.fromEntries(data));\r\n\r\n return response.reduce((base, { data }, index) =\u003E {\r\n data.forEach(([key, point]) =\u003E {\r\n if (!base[key]) {\r\n base[key] = {\r\n x: key,\r\n ...entries.reduce(({points, total}, value) =\u003E ({\r\n points: [...points, value[key] || 0],\r\n total: total \u002B= value[key] || 0\r\n \r\n }), {points: [], total: 0})\r\n };\r\n } \r\n })\r\n\r\n return base;\r\n }, {})\r\n};","IsDeferred":false},{"Name":"sina","Code":"const responseToTimeseries = (response) =\u003E {\r\n // your implementation goes here \r\n const pointHash = {}\r\n \r\n class TimeSeriesPoint {\r\n constructor(x) {\r\n \tthis.x = x\r\n \tthis.points = []\r\n this.total = 0\r\n }\r\n addPoint(point = 0) {\r\n\t\tthis.points.push(point)\r\n this.total \u002B= point\r\n }\r\n }\r\n \r\n // create {x: point} objects for easy accass\r\n const objectified = response.map(({data}) =\u003E Object.fromEntries(data))\r\n \r\n console.log(objectified)\r\n // get only the list of x\u0027s and iterate over them\r\n // could get uniques by converting to a set to avoid extra iterations\r\n response.flatMap(item =\u003E item.data.map(i =\u003E i[0]))\r\n \t\t\t\t.forEach(function(key) {\r\n \t// when encountering a new x, add a point to it for each other data set\r\n // if it\u0027s undefined in a given set, point defaults to 0\r\n \tif (!pointHash[key]) {\r\n \tpointHash[key] = new TimeSeriesPoint(key)\r\n \tobjectified.forEach(function(obj) {\r\n \tpointHash[key].addPoint(obj[key])\r\n })\r\n }\r\n })\r\n return pointHash\r\n};","IsDeferred":false}]}