Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
more 787687
(version: 0)
Comparing performance of:
mina vs sina
Created:
5 years ago
by:
Guest
Jump to the latest result
Tests:
mina
const responseToTimeseries = (response) => { const entries = response.map(({ data }) => Object.fromEntries(data)); return response.reduce((base, { data }, index) => { data.forEach(([key, point]) => { if (!base[key]) { base[key] = { x: key, points: entries.map(e => e[key] || 0), total: entries.reduce((total, value) => total += value[key] || 0, 0), }; } }) return base; }, {}) };
sina
const responseToTimeseries = (response) => { // your implementation goes here const pointHash = {} class TimeSeriesPoint { constructor(x) { this.x = x this.points = [] this.total = 0 } addPoint(point = 0) { this.points.push(point) this.total += point } } // create {x: point} objects for easy accass const objectified = response.map(({data}) => Object.fromEntries(data)) console.log(objectified) // get only the list of x's and iterate over them // could get uniques by converting to a set to avoid extra iterations response.flatMap(item => item.data.map(i => i[0])) .forEach(function(key) { // when encountering a new x, add a point to it for each other data set // if it's undefined in a given set, point defaults to 0 if (!pointHash[key]) { pointHash[key] = new TimeSeriesPoint(key) objectified.forEach(function(obj) { pointHash[key].addPoint(obj[key]) }) } }) return pointHash };
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
mina
sina
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Related benchmarks:
String looping Lionel 1
Large number product of x consecutive digits
Square Every Digit
Square Every Digit, but with toString()
Verifica CNPJ
Comments
Confirm delete:
Do you really want to delete benchmark?