I am a beginner with apps script and am coding an inventory checker which compares the values in one array (quantities we have currently in stock) with another array of set threshold values which represent when each inventory item needs to be reordered.
If the quantity in stock (value of a given element in array 1) is less than or equal to the threshold value (value of same element in array 2), then i will have it do something useful later. for now i'm just sending each comparison result to a new boolean array for testing.
I know that the values in each of my arrays are correct and properly indexed for proper comparison before being sent to this function.
function compareArrays(quantitiesArray, thresholdsArray) {
var boolArray = [];
quantitiesArray.forEach(function(quantity, i) {
var threshold = thresholdsArray[i];
if (quantity <= threshold) {
boolArray.push('TRUE');
}
else {
boolArray.push('FALSE');
}
})
return boolArray;
}
for some reason when my forEach loop compares the values of the two arrays, i am getting incorrect comparison results. for example, logs will show a comparison between quantity = 9000 and threshold = 11000 and it will spit out FALSE, which makes no sense.
i also tried a simple for loop and it spit back the exact same incorrect true/false values. i used a bunch of different Logger.log checks at every point to make sure the correct values from each array are being compared, and everything checks out.
quantitiesArray
andthresholdsArray
– Sudhir Ojha