Yesterday, The Elf Coffee Shop needed our help with their app, but today Santa Claus in person asked us to help The Elf Post Service optimize their shipping algorithm.
There are different sizes for each item and boxes and we have to choose the smallest box that can hold our item. Only one item per box.
MY TIP: Items can be rotated.
This puzzle for me relies on array. It can probably be solved in other ways but my approach was to:
- Calculate the volume of each box and item
- Put the item in our ideal "position", rotating it so the longest size will be the first array item
- if the item "could" fit in the box comparing the volumes, we investigate futher more by checking each side
It would not be necessary to rotate the boxes (like I did), since they are already in our "ideal position" with:
width >= length >= height
Here is my solution with the output.
MEMO FOR ME: At first I used Array.prototype.forEach() instead of Array.prototype.every() but then I discovered that forEach doesn't GIVE A $h!1 about the break instruction.