-
-
Save cesarferreira/3ff2881a4a0eb640a3680ec73d8ef231 to your computer and use it in GitHub Desktop.
medium-get-totals
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const totalTypes = { | |
VIEWS: 2, | |
READS: 3, | |
FANS: 5 | |
}; | |
const getTotal = tableColumn => | |
[ | |
...document.querySelectorAll( | |
`td:nth-child(${tableColumn}) > span.sortableTable-number` | |
) | |
] | |
.map(e => parseInt(e.getAttribute("title").replace(/,/g, ""), 10)) | |
.reduce((a, b) => a + b, 0); | |
console.log({ | |
totalViews: getTotal(totalTypes.VIEWS), | |
totalReads: getTotal(totalTypes.READS), | |
totalFans: getTotal(totalTypes.FANS) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment