Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

94
Views
How to create bundle / combo discount logic in JavaScript

I am trying to solve a question for interview preparation. I am struggling to find the right data structure and logic to solve this.

The question is as follows

There are inputs array of the format: ["date, item"]. For example:

[["10212021", popcorn], ["10222021", popcorn], ["10212021", soda],["10212021", popcorn],["10212021", soda]]

On the same day if there are popcorn and soda both purchased, then it costs 9 dollars as a bundled price. else soda is 2.5 dollars, popcorn is 8 dollars.

You need to calculate the total price based on these criteria and return that as output.

My initial train of thought

  1. Have each item tuple - date and item in a hashtable or dictionary
  2. if a corresponding item exists with the same date for the combo apply discount
  3. deduct combo price from total

I am a beginner in JS please advise.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!