I have an array with elements structured like this:
var x = 17;
var arr = [{ value:2, quantity: 4 }, { value:8, quantity: 1 }, { value:3, quantity: 3 }];
How can I identify the indexes of elements that would add up to equal the x
number? For example, in this case the desired output would be:
[1, 3, 3, 3]
The goal is to have the lowest length possible for the returned array, such as [0, 0, 0, 1, 2]
or [0, 0, 0, 0, 2, 2, 2]
.