Instantly share code, notes, and snippets.

Embed
What would you like to do?
dev.to top posts analysis script
// import posts from https://gist.github.com/Chun-Yang/c19fd8c3209212fd820831a9e816a9d7
posts = []
// authors
authorsMap = {}
posts.forEach(post => {
authorsMap[post.author] = authorsMap[post.author] || {author: post.author, reactionsCount: 0, commentsCount: 0};
authorsMap[post.author].reactionsCount += post.reactionsCount;
authorsMap[post.author].commentsCount += post.commentsCount;
})
authorsArray = Object.values(authorsMap)
console.log('=== Authors sort by reactionsCount:')
authorsArray.sort((a1, a2) => a2.reactionsCount - a1.reactionsCount)
console.log(authorsArray.slice(0, 10).map(a => [a.author, a.reactionsCount].join(', ')))
console.log('=== Authors sort by commentsCount:')
authorsArray.sort((a1, a2) => a2.commentsCount - a1.commentsCount)
console.log(authorsArray.slice(0, 10).map(a => [a.author, a.reactionsCount].join(', ')))
// tags
tagsMap = {}
posts.forEach(post => {
post.tags.forEach((tag) => {
tagsMap[tag] = tagsMap[tag] || {tag, count: 0}
tagsMap[tag].count++
})
})
tagsArray = Object.values(tagsMap)
console.log('=== Tags:')
tagsArray.sort((t1, t2) => t2.count - t1.count)
console.log(tagsArray.slice(0, 10).map(a => [a.tag, a.count].join(', ')))
// has number or not in post titles
percentHasNumber = posts.filter((p) => p.title.match(/[0-9]/)).length / posts.length
// vim vs emacs
vimPostsCount = posts.filter((p) => p.tags.includes('#vim') || p.title.match(/vim/i)).length
emacsPostsCount = posts.filter((p) => p.tags.includes('#emacs') || p.title.match(/emacs/i)).length
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment