Code Monkey home page Code Monkey logo

fetch_rewards_challenge's Introduction

fetch_rewards_challenge

Background

Our users have points in their accounts. Users only see a single balance in their accounts. But for reporting purposes we actually track their points per payer/partner. In our system, each transaction record contains: payer (string), points (integer), timestamp (date). For earning points it is easy to assign a payer, we know which actions earned the points. And thus which partner should be paying for the points. When a user spends points, they don't know or care which payer the points come from. But, our accounting team does care how the points are spent.

There are two rules for determining what points to "spend" first:

  • We want the oldest points to be spent first (oldest based on transaction timestamp, not the order they’re received)
  • We want no payer's points to go negative.

We expect your web service to provide routes that:

  • Add transactions for a specific payer and date.
  • Spend points using the rules above and return a list of { "payer": , "points": } for each call.
  • Return all payer point balances. Note:
  • We are not defining specific requests/responses. Defining these is part of the exercise.
  • We don’t expect you to use any durable data store. Storing transactions in memory is acceptable for the exercise.

Example

  1. Suppose you call your add transaction route with the following sequence of calls:
  • { "payer": "DANNON", "points": 1000, "timestamp": "2020-11-02T14:00:00Z" }
  • { "payer": "UNILEVER", "points": 200, "timestamp": "2020-10-31T11:00:00Z" }
  • { "payer": "DANNON", "points": -200, "timestamp": "2020-10-31T15:00:00Z" }
  • { "payer": "MILLER COORS", "points": 10000, "timestamp": "2020-11-01T14:00:00Z" }
  • { "payer": "DANNON", "points": 300, "timestamp": "2020-10-31T10:00:00Z" }
  1. Then you call your spend points route with the following request:
  • { "points": 5000 }
  1. The expected response from the spend call would be: [ { "payer": "DANNON", "points": -100 }, { "payer": "UNILEVER", "points": -200 }, { "payer": "MILLER COORS", "points": -4,700 } ]

  2. A subsequent call to the points balance route, after the spend, should return the following results: { "DANNON": 1000, "UNILEVER": 0, "MILLER COORS": 5300 }

fetch_rewards_challenge's People

Contributors

lkriffell 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.