My idea is to subtract the value of taxBase
from each number in the array and keep only the positive result as a new variable for future use.
If we are talking about subtraction and not comparison, then yes, you can definitely do that. Here's a simple method using a for
loop:
var index, val;
var taxBase = base * 26;
var bt = [37001,80001,180001];
var results = [];
for (index = 0; index < bt.length; ++index) {
val = bt[index] - taxBase; // Perform subtraction and store result in `val`
if (val > 0) { // Is the result positive?
results.push(val); // If yes, add it to the results array
}
}
Considering the context of taxes and the significance of the bt
values, it seems like your ultimate goal might be to determine the first value in bt
that is greater than the calculated taxBase
. If this is the case, here's how you can achieve it:
var index;
var taxBase = base * 26;
var bt = [37001,80001,180001];
var entryToUse;
for (index = 0; index < bt.length; ++index) {
// Is taxBase less than this entry?
if (taxBase < bt[index]) {
// If yes, save this entry
entryToUse = bt[index];
// Exit the loop
break;
}
}
Upon executing the above code, the value stored in entryToUse
will be either 37001
, 80001
, 180001
, or undefined
if taxBase
exceeds all entries in the array.