Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.

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