Array Functions

avg

Calculates the average value of the data contained in an array. Its behavior is defined for numeric element types only. The return type will be the same as the type of the array.

Arguments
Array
array to be averaged
Returns The average value of all numeric elements of the array. If the array is empty, returns 0 (zero). If the array contains null elements, they are ignored in the calculation. With an array containing only null elements, the function will also return 0 (zero).
The following will display 19.42:
array as Decimal [] = [10.49, 13.78, null, 33.99]
display avg(array)

count

Counts the number of non-null elements contained in an array.

Arguments
Array
array to be counted for non-null elements
Returns An Integer value with the index. If the element is not found, returns -1. If the array is empty, returns -1.
The following will display 3:
array as Int[]=[22,33,null,55]
display count(array)

indexOf

This function returns the index of the first occurrence of an element in the array. The array index starts at zero for the first element.

Arguments
Array
array to be searched for matching elements
Any
the element to be searched
Returns An Integer value with the index. If the element is not found, returns -1. If the array is empty, returns -1.
The following will display 1:
array as String[] = ["Hello","!!!","world","!!!"]
display indexOf(array, "!!!")

lastIndexOf

This function searches the array for matching elements, and returns the index of the element's last occurrence. The array index starts at zero for the first element.

Arguments
Array
array to be searched for matching elements
Any
the element to be searched
Returns An Integer value with the index. If the element is not found, returns -1. If the array is empty, returns -1.
The following will display -1:
	array as String[] = ["Hello","world","!!!"]
	display indexOf(array, "happy")
	
The following will return 2:
	array as String[] = ["Hello","world","!!!"]
	display indexOf(array, "!!!")
	
The following will display 3:
array as String[] = ["Hello","!!!","world","!!!"]
display lastIndexOf(array, "!!!")

length

This function returns the length of the array.

Arguments
Array
array from which the length will be obtained
Returns An Integer value with the number of elements in the array. If the array is empty, returns 0 (zero).
The following will return display 4:
	array as Int[] = [7,8,9,10]
	display length(array)
	

max

This function returns the maximum element of the array. The element type must have a defined sorting order. The return type will be the same as the type of the array.

Arguments
Array
array from which the maximum value will be obtained
Returns The maximum element of the array. If the array is empty, returns a null value.
For example, the following will display "D":
array as String[]=["A","B","C","D"]
display max(array)

min

This function returns the minimum element of the array. The element type must have a default ordering defined. The return type will be the same as the type of the array.

Arguments
Array
array from which the minimum value will be obtained
Returns The minimum element of the array. If the array is empty, returns a null value.
For example, the following will display 22:
array as Int[]=[22,33,44,55]
display min(array)

sum

Calculates the sum of all the elements of the array. This function is defined for numeric element types only.

Arguments
Array
array to be summed
Returns The sum of all the elements of the array. If the array has no elements, returns 0 (zero).
For example, the following should display 4394:
	
array as Int[]=[112,3233,454,595]
display sum(array)