You could optimize the for loop by hoisting your iterator and posts.length. It would take much less time if you didn't have to check posts.length every time.
for(let i=0; i<posts.length; i++) {
posts[i].upvotes = (posts[i].upvotes +posts[i].commentCount)/divider;
}
Would take less time implemented this way:
var i;
const len = posts.length;
for(i=0; i<len; ++i) {
avg += (posts[i].upvotes +posts[i].downvotes +posts[i].commentCount)/3;
}
You could optimize the for loop by hoisting your iterator and posts.length. It would take much less time if you didn't have to check posts.length every time.
Would take less time implemented this way: