{"ScriptPreparationCode":null,"TestCases":[{"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 // 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},{"Name":"mina","Code":"const responseToTimeseries = (response) =\u003E {\r\n return response.reduce((base, { data }, index) =\u003E {\r\n data.forEach(([key, point]) =\u003E {\r\n const series = base[key];\r\n\r\n if (series) {\r\n const { points, total } = series;\r\n const pointsDiff = index - points.length;\r\n // Add enough \u0027buffer\u0027 0s to match the current index\r\n const buffer = pointsDiff ? new Array(pointsDiff).fill(0, 0, pointsDiff) : [];\r\n\r\n base[key] = {\r\n ...series,\r\n points: [...points, ...buffer, point],\r\n total: total \u002B point\r\n }\r\n } else {\r\n base[key] = {\r\n // Pad as many 0s as needed to match the current index (length)\r\n // [0, point] satifies the tests, but data can be crazy sometimes \uD83E\uDD2F\r\n // This feels a bit more reliable\r\n points: new Array(index).fill(0, 0, index).concat(point),\r\n total: point,\r\n x: key,\r\n }\r\n }\r\n })\r\n\r\n return base;\r\n }, {});\r\n};","IsDeferred":false}]}