Sort using a custom comparator: Difference between revisions

Line 252:
 
=={{header|J}}==
 
Input is to be a list of boxed character lists. The output will be in the same structure.
<br>Case-insensitivity is obtained using <tt>lower</tt>, a verb taken from [[Change string case]]. Standard utilities <tt>tolower</tt> or <tt>toupper</tt> may be substituted.
 
mycmp=: 31 : 0'/:u'
wt=. ;#&.> y
length_and_case =: (# ; lower)&>
;(/:&.> lower L: 0) (\: ~. wt) { wt </. y
strings=: 'Here';'are';'some';'sample';'strings';'to';'be';'sorted'
)
length_and_case mycmp strings
Example:
+---+----+------+---+--+---+----+-----+-----+--+----+----------+----------+---+-----+-----+----+
]strings=: ;: 'Sed quae tandem est in hac urbe tanta domus ab ista suspicione religionis tam vacua atque pura'
|be|to|are|Here|some|sample|sorted|strings|
+---+----+------+---+--+---+----+-----+-----+--+----+----------+----------+---+-----+-----+----+
+---+----+------+---+--+---+----+-----+-----+--+----+----------+----------+---+-----+-----+----+
|Sed|quae|tandem|est|in|hac|urbe|tanta|domus|ab|ista|suspicione|religionis|tam|vacua|atque|pura|
+---+----+------+---+--+---+----+-----+-----+--+----+----------+----------+---+-----+-----+----+
mycmp strings
+----------+----------+------+-----+-----+-----+-----+----+----+----+----+---+---+---+---+--+--+
|religionis|suspicione|tandem|atque|domus|tanta|vacua|ista|pura|quae|urbe|est|hac|Sed|tam|ab|in|
+----------+----------+------+-----+-----+-----+-----+----+----+----+----+---+---+---+---+--+--+
 
=={{header|Java}}==
Anonymous user