So, I have an array that looks something like this:
var x = 17;
var arr = [{ value:2, quantity: 4 }, { value:8, quantity: 1 }, { value:3, quantity: 3 }];
My question is how can I find the indices of those elements that will be equal to the number xafter adding their values. In this case, the refund will be:
[1, 3, 3, 3]
Of course, this can also be done with [0, 0, 0, 1, 2]or [0, 0, 0, 0, 2, 2, 2], but a lower length of the returned array will be better.
source
share