Set number input max based on the sum of 4 inputs using jquery and reset quantity

I followed this thread Set number input max based on the sum of 4 inputs using jquery and the code below works as expected:

$("input[type='number'].wapo-product-qty").val(0); 
$("input[type='number'].wapo-product-qty").change(function () {
$.each($("input[type='number'].wapo-product-qty"), function (index, element) {
    var total = 0;
    $.each($("input[type='number'].wapo-product-qty").not($(element)), function 
(innerIndex, innerElement) {
        total += parseInt($(innerElement).val());
    });
    if ($(element).val() > 6 - total) {
        alert("The total value for all inputs can not exceed 6");
                  $(element).val(0);
        return false;
    } else {
        $(element).attr("max", 6 - total);
        }
    });
});

But I need the quantity selector to start from 0 and not from 1.

I added this for that, but I don’t know is the best approach:

 $("input[type='number'].wapo-product-qty").val(0); 

Once the condition of the maximum number of quantities is reached, the fields for which the quantity has not been selected with the selector are reset to 0.

For example in my case:

4 input fields: 

0 -> change to 2
0 -> change to 2
0 -> change to 2
0 -> change to 1 -> we are over 6, condition reached

But the last input it remains 1, so I would like to reset to 0 for this reason.

Thanks