Polymorphic function to check if an array is sorted