Copy link to clipboard
Copied
What should be correct number for that example, 1 or 7?
i = 1; while(7 % ++i); i
or:
i = j = 7; while(j % --i); i
Or else you want:
!(7 % 2)
so:
!(20 % 4)
Copy link to clipboard
Copied
What is preferred result for above example, 3 and 4?
Copy link to clipboard
Copied
What is preferred result for above example, 3 and 4?
By @Kukurykus
Thank you for the reply.
Neither is preferred. I was thinking of a conditional or try/catch error to cancel the script if the input length is not evenly divisible by the set length.
I don't know how to express it better...
To pass, the number must be an integer.
To pass, the input count has to divide into "sets".
If there were 33 input files batched in sets of 3, the result is 11 which is a pass. 32 or 34 input files divided by 3 would fail.
If there were 20 input files batched in sets of 4, the result is 5, which is a pass. 19 or 21 input files would be a fail when divided by 4.
The division number could be odd or even, however, it is always an integer. The input count is also an integer (as one can't have less than a single file) and could be odd or even.
Hope this makes sense.
Copy link to clipboard
Copied
What should be correct number for that example, 1 or 7?
i = 1; while(7 % ++i); i
or:
i = j = 7; while(j % --i); i
Or else you want:
!(7 % 2)
so:
!(20 % 4)
Copy link to clipboard
Copied
Haha, I'm lost! Thank you for sticking with me... Math is not my strong area.
The correct answer is an integer, that is cleanly divided from the input from the sets. This is dependent on both variables, will will depend on an unkown length of input images and an uknown set value which divides into thje input length.
Am I over thinking this? If the calculated division number is not an integer the script should cancel/fail/exit. Is testing to see if the set evenly divides into the input length redundant?
At the moment the manual check is:
// Manually validate the input count vs. output count
var inputCount = fileList.length;
var cancelScript = confirm(inputCount + " input files stacked into sets of " + setQty + " will produce " + inputCount / setQty + " file sets. Press 'Yes' to continue or 'No' to cancel.");
// Test if no returns false, then terminate the script
if (cancelScript === false) {
alert('Script cancelled!');
return;
}
Copy link to clipboard
Copied
I updated my post of that you probably look for.
Copy link to clipboard
Copied
Thank you!
Keeping in mind that I only know enough about scripting to be dangerous... I am testing your suggestion:
var inputCount = 20;
var setQty = 4;
var theResult = !(inputCount % setQty);
alert(theResult);
Which reslts in True!
var inputCount = 19;
var setQty = 4;
var theResult = !(inputCount % setQty);
alert(theResult);
Results in False...
This is looking promising, thank you, now all I need to do is work out how to construct the try/catch or if/else.
Copy link to clipboard
Copied
inputCount = 20, setQty = 4, inputCount % setQty ? 'exit' : 'enter'
Copy link to clipboard
Copied
This is what I came up with as I just repurposed my previous manual check:
// Validate the input count vs. output count
var inputCount = fileList.length;
// Thanks to Kukurykus for the %
var cancelScript = !(inputCount % setQty);
alert(inputCount + ' input files stacked into sets of ' + setQty + ' will produce ' + inputCount / setQty + ' file sets.');
// Test if false, then terminate the script
if (cancelScript === false) {
alert('Script cancelled as the quantity of input files are not evenly divisible by the set quantity.');
return;
}
I'll look into your suggestion, thank you!
Now I need to go find what the % operator does.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Thank you, I found it here as well under modulus/remainder:
https://www.w3schools.com/js/js_arithmetic.asp
However without your help that would have been a major stretch from the "textbook answer" to a "working answer".