Snippet. Vala. Find Largest Integer in Array of integers

This convenient Vala function will return the largest integer from array of integers.

//======================== START OF FUNCTION ==========================//
// FUNCTION: array_get_max_int                                         //
//=====================================================================//
int array_get_max(int[] array){
    int max = array[0];

    for (int i = 0; i < array.length; i++) {
        if (array[i] > max) {
            max = array[i];
        }
    }

    return max;
}
//=====================================================================//
// FUNCTION: array_get_max_int                                         //
//========================= END OF FUNCTION ===========================//

Example

int[] array = {1, 2, 3, 4};

int max = array_get_max_int(array);

Updated on: 16 Apr 2024