Finds the largest and smallest element of an array