http://simple-hn-app.herokuapp.com/
- Maintain a list of topics and its upvotes/downvotes
- Allow the user to submit topics (string of <= 255 chars).
- Allow multiple upvotes or downvotes of topic.
- Always return a list of top 20 topics (sorted by upvotes, descending) on the homepage
For an actual HN app, a database or data store. Reddit uses Solr. For this simple clone, with k=20, I can think of 2 more efficient methods:
Not feasible when n is large, but for this clone n will not get large enough for this to matter.
Insertion into tree/heap and removal everytime topic is upvoted...
- Tree: Average O(log n) insertion + O(log n) removal
- Heap: Average O(1) insertion + O(log n) removal (if we have direct pointer to that node we want to remove; otherwise it's O(n)) Extracting k highest nodes O(k log n) or actually even O(k * 1) everytime homepage is requested.
Sort array upon display of top 20, with JavaScript Array.prototype.sort().
The project is separated into ./client
, which contains a Nuxt.js (framework for SSR Vue.js apps) app, and ./server
, which contains a Express REST API. Refer to the README's in the respective subfolders for details pertaining to each part.
Nuxt.js app and Express app hosted with Heroku.