Giter Site home page Giter Site logo

red-clone's Introduction

Red-Clone

Reddit/Digg clone for Carousell's coding challenge.

Heroku demo: https://red-clone.herokuapp.com

Code Ownership

The skeleton of the repository was generated with express-generator and create-react-app. I wrote the rest.

Installation

Clone and cd into repository:

git clone https://github.com/PukiPuki/red-clone.git
cd red-clone

Install dependencies on both backend and frontend:

npm install 
cd client
npm install 
cd ..

From the root directory(not inside client) build the frontend files that will be served by express:

npm heroku-postbuild

Start the server:

npm start

Run tests:

npm test

Assumptions about the problem

Reddit is a big app, they have many users. Creating, retrieval and voting has to be as efficient as possible. The amount of retrieval and voting will be far greater than creating of topic so I focused on creating something to help speed up these portions.

Data Structure and Sorting Algorithm

Here is a summary of the data structure used by dataStructure to store and manage the threads.

  • The threads are objects.
  • An array, rank maintaining the sorted invariant have indexes pointing to the object.
  • To retrieve the threads, a Map aptly named map is used.
  • Another map, firstLastIndex of votes to their first and last indexes is used to allow O(1) upvote and downvote.

O(1) Upvote/Downvote

This method was inspired by quicksort's partition method of moving things. This is based on the assumption that there are many many number of threads with same number of votes. Think thousands of threads with 0 votes, most blank reddit posts just die out.
The firstLastIndex is a map of vote to first and last index of a partition indicating where a partition starts and end. When upvoting or down voting happens just swap it with the first or last index and the rest is book keeping.

O(1) Retrieval

Map is used, trivially O(1).

O(1) Create

Array.push() is used to append new thread to the end of rank Votes indexes are retrieved through a map then updated

red-clone's People

Contributors

tomatocream avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.