Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

105
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda