covidatlas / li

Next-generation serverless crawler for COVID-19 data
Apache License 2.0
57 stars 33 forks source link

Fix sortKeys helper function #589

Closed joliss closed 4 years ago

joliss commented 4 years ago

I noticed an issue in the test code when I was working on another patch and it reported a test failure:

li

I tracked this down to the sortKeys helper function, which this pull request fixes!

Current:

>   function sortKeys (item) {
...     const keys = Object.keys(item).sort()
...     return keys.reduce((hsh, k) => {
.....       return { ...hsh, [k]: item[k] }
.....     })
...   }
undefined
> sortKeys({foo: 1, bar: 2})
{ '0': 'b', '1': 'a', '2': 'r', foo: 1 }
>

My patch:

>   function sortKeys(item) {
...     const ordered = {}
...     for (let key of Object.keys(item).sort()) {
.....       ordered[key] = item[key]
.....     }
...     return ordered
...   }
undefined
> sortKeys({foo: 1, bar: 2})
{ bar: 2, foo: 1 }
>