Git Product home page Git Product logo

examplecode's Introduction

Solution

This express server stands up an endpoint at /value that takes the following args: PATH /value/100000 (initial value of vehicle) QUERY ?age (age of vehicle in count of months) QUERY ?owners (count of vehicle owners) QUERY ?mileage (total mileage as integer) QUERY ?collisions (total number of collisions)

Example query:

http://localhost:3000/value/12500.35?&age=60&owners=1&collisions=1&mileage=100000

Expected output:

{ initialValue: "12500.35", estimatedValue: "5145.14" }

TASK

You are tasked with writing an algorithm that determines the value of a used car, given several factors.

AGE:

Given the number of months of how old the car is, reduce its value one-half (0.5) percent. After 10 years, it's value cannot be reduced further by age. This is not cumulative.

MILES:

For every 1,000 miles on the car, reduce its value by one-fifth of a percent (0.2). Do not consider remaining miles. After 150,000 miles, it's value cannot be reduced further by miles.

PREVIOUS OWNER:

If the car has had more than 2 previous owners, reduce its value by twenty-five (25) percent. If the car has had no previous owners, add ten (10) percent of the FINAL car value at the end.

COLLISION:

For every reported collision the car has been in, remove two (2) percent of it's value up to five (5) collisions.

Reduction Order:

Each factor should be off of the result of the previous value in the order of

  1. AGE
  2. MILES
  3. PREVIOUS OWNER
  4. COLLISION

E.g., Start with the current value of the car, then adjust for age, take that result then adjust for miles, then collision, and finally previous owner.

Note that if previous owner, had a positive effect, then it should be applied AFTER step 4. If a negative effect, then BEFORE step 4.

Write a simple Node/Express server that will accept the parameters as JSON, perform the calculation and return the car value as a JSON Object. No authentication or authorization is required.

PERSISTENCE:

No data persistence is required.

examplecode's People

Contributors

studnicky avatar

Watchers

 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.