Sort using a custom comparator: Difference between revisions

Content added Content deleted
m (syntax highlighting fixup automation)
No edit summary
Line 1,975: Line 1,975:
["strings", "sample", "sorted", "here", "Some", "are", "be", "to"]
["strings", "sample", "sorted", "here", "Some", "are", "be", "to"]
</pre>
</pre>



=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
include "NSLog.incl"

local fn CustomComparator( obj1 as CFTypeRef, obj2 as CFTypeRef, context as ptr ) as NSComparisonResult
NSComparisonResult result = fn StringCaseInsensitiveCompare( obj1, obj2 )
end fn = result

local fn ComparatorStringSort( wordString as CFStringRef ) as CFStringRef
CFArrayRef stringArray = fn StringComponentsSeparatedByString( wordString, @" " )
CFArrayRef sortedArray = fn ArraySortedArrayUsingFunction( stringArray, @fn CustomComparator, NULL )
CFStringRef sortedStr = fn ArrayComponentsJoinedByString( sortedArray, @"\n" )
end fn = sortedStr

NSLog( @"%@", fn ComparatorStringSort( @"The quick brown fox jumped over the lazy dog's back" ) )

HandleEvents
</syntaxhighlight>
{{output}}
<pre>
back
brown
dog's
fox
jumped
lazy
over
quick
The
the
</pre>





=={{header|Fōrmulæ}}==
=={{header|Fōrmulæ}}==