Data Formatter for Average on Client Side

I have a two dimensional array of data which is read from a server connect. So consider it a number of rows and columns like this:

'1'   'banana'    'green'   '7'
'3'   'pear'      'yellow'  null
'6'   'orange'    'purple'  '4'

I would like to find the average of the first column (1,3,6) and the last column (7,4) on the client side.

Is there an average function on the client side that I can use? Or do I need to do the maths myself with .sum() and .count()?

If the latter, can anyone remind me how to do a .where() where the condition is [not null]?

How do I handle the conversion from text to number for numbers?

Thanks!

Antony.

Antony, there is an Average formatter available which does exactly this:

Also I see your values are stings so you will need to convert them to numbers when doing the calculations …

Thanks @Teodor!

So would it look like this?

responses_activity.data.responses.avg(`response.toNumber()`)

And would this leave out the entry with a null value?

Best wishes,
Antony.

In my experience it does seem to leave out null values.

Oh yes, I see it now… it was hidden because of the .where() bug we found a few days ago that leaves the expression no longer recognised as an array!