GithubHelp home page GithubHelp logo

shipment-optimizer's Introduction

Shipment Optimizer

The Shipment Optimizer is a command line tool written in NodeJS that allows you to optimize your shipments between multiple locations with an equal amount of drivers.

Getting Started

Installation

  1. Clone the repo to your local machine in the directory of your choice (e.g. ~/dev/)
    git clone https://github.com/rhon3n/shipment-optimizer.git
  2. Change to the root directory of the project
    cd shipment-optimizer
  3. Install NPM packages
     npm install
  4. Place your destinations and drivers files (be sure they are .txt files) in the root directory of the project. See the Using the Shipment Optimizer section for more information on the format of these files.

Using the Shipment Optimizer

Once installed, it can be used by running the following command in the terminal of your choice the root directory of the project:

## in ~/../shipment-optimizer/
node app.js <name_of_destinations_file> <name_of_drivers_file>

The first argument is expected to be the name of the destinations file, and the second argument is expected to be the name of the drivers file.

Each of these files should be .txt files with entries seperated by newlines and should be present in the root directory of the project

The output will be a console log of the total suitability score and a list of drivers matched with destinations one per line, with the driver's name followed by the destinations they will be delivering to.

Testing

The Shipment Optimizer uses Mocha for testing. To run the tests, run the following command in the root directory of the project:

## in project root
npm test

Assumptions

  • The number of drivers is equal to the number of destinations
  • The letter y is considered a consonant
  • White space is included in the length of a string
  • The filetype of the input files is .txt
  • User is comfortable using the command line

Solution Formation

Steps I thought of and executed to solve the problem:

Step 1: Address the problem

  1. Create a function, calculateSuitabilityScore, to calculate and return the suitability score of a driver for a given destination.
  2. Create a function, optimizeShipments, to optimize matching between destinations and drivers based on suitability score.
  3. Create a function, calculateTotalSuitabilityScore, that will return the total suitability score of a given set of matches.

Step 2: Render the output

  1. Create a function that handles the input and output of the program.
    • Check for valid input.
    • Read the input files.
    • Call the functions created in Step 1.
    • Render the output.

Libraries/Tools used

  • Written in Node using import syntax. Tested using Node.js v18.15.0
  • Using Mocha v10.2.0 for testing.
  • Console output styled using Chalk v5.3.0.

Decisions and Tradeoffs

  • I decided to go with a procedural approach to solving the problem, as I felt it would be easier to test and reason about.
  • There are areas of the code that could be improved. However, given the time constraints, I decided to focus on getting the code working and tested.
  • I originally wanted to use TypeScript to type check the code. However, since the problem was relatively simple, I decided to use plain JavaScript to save time and reduce complexity.
  • I decided to use a simple console output to display the results. If this were a real-world project, I would have created a UI to make it easier to use.

Future Improvements

This is a coding assessment with a purposely limited scope. If it were a real-world project, I would consider the following improvements:

  • Adding more tests to cover edge cases.
  • Adding TypeScript to type check the code.
  • Adding input validation.
  • Adding a UI to make it easier to use.
  • Adding CI/CD to automate testing and deployment.

shipment-optimizer's People

Contributors

rhon3n avatar

Watchers

 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.