I have an array of products id, and 2 arrays with product id in key and price and unique flag in values.
I would like to have all unique combinations of products under a given total limit price :
- a product could be several times in combination, except if it is flagged as unique
- combination should be sorted by product id
- a valid combination is one to the which we can't add product
Sample:
products = [1, 2, 3];
productPrices = {1:10, 2:15, 3:10};
productUnique = {1:true, 2:false, 3:false};
limitPrice = 40;
expected result = [[1,2,2],[1,2,3],[1,3,3,3],[2,2,3],[2,3,3],[3,3,3,3]];
How can I obtain this result in javascript if possible ? Thanks for the help.