Nested conditionals
There are times it makes sense to nest conditionals, but in tehthe case of your code, it's unnecessary.
This:
if(i < 2) { prod *= arr[i]; ans.push(-1); } else { if(i === 3) { prod *= arr[i]; ans.push(prod); } else if(arr[i] < helper[0]) { ans.push(prod); } else { const min = helper.shift(); prod /= min; prod *= arr[i]; ans.push(prod); } }
Is better written:
if (i < 2) {
prod *= arr[i];
ans.push(-1);
}
else if (i === 3) {
prod *= arr[i];
ans.push(prod);
}
else if (arr[i] < helper[0]) {
ans.push(prod);
}
else {
const min = helper.shift();
prod /= min;
prod *= arr[i];
ans.push(prod);
}