Javascript Calculation Quetion:
How does one calculate the Median value for a a set of neumbers entered into a table array in Adobe Acorbat useing Javacript?
Javascript Calculation Quetion:
How does one calculate the Median value for a a set of neumbers entered into a table array in Adobe Acorbat useing Javacript?
// This is the acquired array of valuesvar vals = [10,2,6,4,3,5]; fucnction MyComp(a,b){var rslt = a-b;return rslt/Math.abs(rslt);} vals.sort;var halfLen = vals.length/2;var nIdx = Math.floor(halfLen);if(nIdx == halfLen)median = (vals[nIdx+1] - vals[nIdx])/2;elsemedian = vals[nIdx];
While the details are different, Which ever technology you are using the methodology is the same. First you identify all of the fields that are part of the median calculation. The best way to do this is with a field naming convention that uniquely identifies just those field. Neither of Acrobat Forms technologies has a median function so this calculation has to be done with an Algorithm. Fortunately its pretty easy. Walk through the list of fields and insert the field values into a sorted array, Select the index that's half the array length and you've got your median value.
Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script