Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

What is the Javascript for averaging?

Avatar

Level 1

What is the correct scripting for averaging a series of numbers in LiveCycle 8.2 - Javascript.

Thanks!

2 Replies

Avatar

Level 10

function average()
{
   var items = average.arguments.length;
   var sum = 0;
   for (i = 0; i < items;i++)
   {
      sum += average.arguments[i];
   }
   return sum / items;
}

If you put this in a script object called MathUtils you can call it using;

MathUtils.average(1,2,3);

You can pass as many arguments as you like.

I generally use JavaScript myself but feel I should point out that FormCalc does have an inbuild Avg function