Code Monkey home page Code Monkey logo

lucky-cart-tech-assessment's Introduction

Lucky Cart โ€“ Technical Assessment

In this assessment, you have to calculate cart eligibility to a campaign. To do so, you have to compare criteria with cart data.

How to do the assessment

  1. Read this entire documentation
  2. Clone this repository
  3. Open src/eligibility.service.js file and edit isEligible(cart, criteria) method.
  4. Run npm start or node index.js ./cart-test.json ./criteria-test.json to check results
  5. You can edit cart-test.json or criteria-test.json for more tests.

You are free to use internet (Google, StackOverflow, ...), to ask question or do whatever you want to pass this assessment.

๐Ÿ’ก Advice: be lean. Develop one condition at a time.

Carts

A cart represent an online transaction. It has many parameters such as cartId, shopperId, products, ...

Cart example:

{
  "cartId": "cart-id",
  "shopperId": "shopper-id",
  "date": "2021-10-06T18:35:42.000Z",
  "totalAti": 99.8,
  "promoCode": "voucher-42",
  "products": [
    {
      "productId": "5449000054227",
      "quantity": 20,
      "unitPriceAti": 2.5,
      "totalPriceAti": 50
    },
    {
      "productId": "3099873045369",
      "quantity": 2,
      "unitPriceAti": 24.9,
      "totalPriceAti": 49.8
    }
  ]
}

Criteria

Criteria are a list of key-conditions values (eg: {key1: condition1, key2: condition2}). If all the conditions are fulfilled then the cart is eligible.

To validate a condition, you have to compare the condition with the value of the same key in the cart. If there is some "." in the key, compare to the value of the sub-object (eg: { "products.productId": condition } in criteria means to check { products: { productId: value } } or { products: [{ productId: value }] } in cart).

Available condition types:

  • Basic condition (eg: total: 20) matches when total == 20;
  • gt, lt, gte, lte matches respectively when cart value is greater, lower, greater or equal, lower or equal;
  • in (followed by an array) matches when at least one of the cart values is in the following array;
  • and (followed by at least two conditions) matches when every following conditions match;
  • or (followed by at least two conditions) matches when at least one of the following conditions matches.

โš ๏ธ Conditions are typeless! { total: 20 } matches { total: "20" } and { total: 20.0 }.

Criteria example:

{
  "shopperId": "shopper-id",
  "totalAti": {
    "gt": 50
  },
  "products.productId": {
    "in": ["5449000054227"]
  },
  "date": {
    "and": {
      "gt": "2021-01-01T00:00:00.000Z",
      "lt": "2021-12-31T23:59:59.000Z"
    }
  }
}

Examples

Criteria:

{
  "shopperId": "eligible-shopper-id",
  "totalAti": {
    "gt": 50
  }
}

Eligible cart:

{
  "cartId": "eligible-cart-id",
  "shopperId": "eligible-shopper-id",
  "totalAti": 100
}

Not eligible cart:

{
  "cartId": "not-eligible-cart-id",
  "shopperId": "not-eligible-shopper-id",
  "totalAti": 25
}

lucky-cart-tech-assessment's People

Contributors

vincentoliveira avatar lc-yanis 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.