1
0 Comments

Tutorial: Sorting ~1761 subreddits to see which subreddits are popular

Hi, I am researching of subreddits to make my next product. I want to get an overview of how I sort subreddits.

This will use vanilla JS.

1. grab the subreddits data from here https://pastebin.com/XVBDM4jn (copy the raw paste data)

Copy the json data to your html code like this (and don't forget to parse it)

<script>
let json_subreddits = JSON.parse(`//the copy pasted json data`)
</script>

2. We need to sort the subreddits from most popular to least popular. We need to use sort() function.

But the problem is our data is an object, and not an array.
To convert it, we need to iterate the object

let json_subreddits = JSON.parse(`the copy pasted json data`);

let sortable = [];
for (let subreddits in json_subreddits) {
sortable.push([subreddits, json[subreddits]]);
}

now we have an array

3. Use sort function

let json_subreddits = JSON.parse(`the copy pasted json data`);

let sortable = [];
for (let subreddits in json_subreddits) {
sortable.push([subreddits, json[subreddits]]);
}

sortable.sort(function(a, b) {
    return b[1] - a[1];
// this will return from big to small. to inverse it, just switch the a and b
// return a[1] - b[1];
});

4. Console.log(sortable) to see the result

And you can view subreddits in your console. Enough to give you which subreddits are popular and which are least popular.

If you like this, you can follow my journey live on Twitter https://twitter.com/RicardoSawir
or follow me on IndieHacker here.

posted to Icon for group Developers
Developers
on January 14, 2021
Trending on Indie Hackers
AI runs 70% of my distribution. The exact stack. User Avatar 98 comments I'm a solo founder. It took me 9 months and at least 3 stack rewrites to ship my SaaS. User Avatar 75 comments Show IH: I'm building a lead gen + CRM tool for web designers targeting local businesses without websites — starting with Spain User Avatar 72 comments I built a URL indexing SaaS in 40 days — here's the honest story User Avatar 57 comments We could see our AI bill, but not explain it — so I built AiKey User Avatar 20 comments We witnessed a sharp spike in our traffic. So much happiness after a long time. User Avatar 15 comments