Created
June 15, 2018 00:09
-
-
Save jamesmacfie/a9548e783870a6f5b5c9a2b319e645b2 to your computer and use it in GitHub Desktop.
Find the most negative comment on Stuff.co.nz articles
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 findTheMostNegativeComment = () => { | |
const voteVals = []; | |
const votes = document.querySelectorAll('.gig-comment-vote-total'); | |
[].forEach.call(votes, (v) => { | |
const val = v.innerHTML; | |
if (val.charAt(0) === '-') { | |
voteVals.push({ | |
text: val, | |
total: parseInt(val.slice(1)), | |
el: v | |
}) | |
} | |
}) | |
if (!voteVals.length) { | |
console.log('There are no negative comments'); | |
return null; | |
} | |
return voteVals.sort((a, b) => b.total - a.total)[0].el | |
// Urgh gross | |
.parentElement.parentElement.parentElement.querySelector('.gig-comment-body').innerHTML; | |
} |
rickysullivan
commented
Jun 15, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment