4 ms·
I wanted a total for the US: console.table([...document.querySelectorAll('.fatitem table .athing')].map(el => [el.textContent.replace(/:.*/,'').trim(), par
by newaccount74 5y ago
I wanted a total for the US:
console.table([...document.querySelectorAll('.fatitem table .athing')].map(el => [el.textContent.replace(/:.*/,'').trim(), parseInt(el.nextSibling.textContent.trim())]).reduce((d, [k,v]) => {d[k]=v + (d[k] || 0); return d}, {}))
I can't figure out how to sort that, though...
- gabrielsroka 5y agoObject.entries https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- newaccount74 5y agoOh, I need to type Object.entries(x) instead of x.entries() Makes sense, otherwise entries would contain itself. Thank you!
- eyelidlessness 5y agoEntries only iterates enumerable items (unless you make something evil). None of the native types with entries in their prototype iterate over that method
- binarynate 5y agoI created a page with the current results that includes a total for the US: https://nate.org/hacker-news-location-poll https://nate.org/hacker-news-location-poll
- Larrikin 5y agoPercentage next to totals would make this perfect
- binarynate 5y agoGood idea—I just added a percentage column, as well as a row at the bottom for the total count
- gabrielsroka 5y agoHaha, great minds think alike. Are you accepting PRs? If so, align=right. Thanks! To see the sorted results: https://gabrielsroka.github.io/hnpoll.html?id=30210378 https://gabrielsroka.github.io/hnpoll.html?id=30210378 Source: https://github.com/gabrielsroka/gabrielsroka.github.io/blob/master/hnpoll.html https://github.com/gabrielsroka/gabrielsroka.github.io/blob/...
- shafkathullah 5y agoJust click on 'Value' in console to sort by value