Skip to content

Latest commit

 

History

History
21 lines (14 loc) · 1.17 KB

README.md

File metadata and controls

21 lines (14 loc) · 1.17 KB

AdventJS - Challenge #3: How many packs of gifts can Santa carry?

You are given a pack of Christmas gifts that Santa Claus wants to deliver to the children. Each gift is represented by a string. Santa Claus has a sleigh that can carry a limited weight, and each gift inside the pack has a weight that is equal to the number of letters in the gift's name.

Santa Claus also has a list of reindeer that can help him deliver the gifts. Each reindeer has a maximum weight limit that it can carry. The maximum weight limit of each reindeer is equal to twice the number of letters in its name.

Your task is to implement a function distributeGifts(packOfGifts, reindeers) that receives a pack of gifts and a list of reindeer and returns the maximum number of gifts that Santa Claus can deliver. Packs of gifts can't be splitted.

const packOfGifts = ['book', 'doll', 'ball']
const reindeers = ['dasher', 'dancer']

// pack weights 4 + 4 + 4 = 12
// reindeers can carry (2 * 6) + (2 * 6) = 24
distributeGifts(packOfGifts, reindeers) // 2

Things to keep in mind:

  • The pack of gifts can't be splitted.
  • Gifts and reindeers names length will always be greater than 0.