Skip to content

Modern Sorting IsSortedBy

Paul Squires edited this page Oct 19, 2026 · 5 revisions

Home › Sorting › Sorting › IsSortedBy

IsSortedBy

Returns true if the Array is already in order by your comparer.

Syntax

IsSortedBy( a, less ) as boolean

Examples

#import "std/containers"
using containers

dim v as Array( of ustring )
v.Push( "fig" ) : v.Push( "pear" ) : v.Push( "banana" )

'' Ordered by length, which is not the same question as alphabetically
print IsSortedBy( v, function( byref x as ustring, byref y as ustring ) as boolean
    return len( x ) < len( y )
end function )               '' true

print IsSorted( v )          '' false -- not in alphabetical order

'' Use the same comparison here that was used to sort, or the answer is
'' about a different ordering than the one that was applied

Library: Sorting
Category: Sorting
Documented under: Procedures

Clone this wiki locally