Sort using a custom comparator: Difference between revisions

Content added Content deleted
m (added a category.)
(Added Wren)
Line 3,227: Line 3,227:
End Sub
End Sub
End Module</lang>
End Module</lang>

=={{header|Wren}}==
{{libheader|Wren-sort}}
<lang ecmascript>import "/sort" for Cmp, Sort

var cmp = Fn.new { |s, t|
if (s.count < t.count) return 1
if (s.count > t.count) return -1
return Cmp.insensitive.call(s, t)
}

var strings = ["Here", "are", "some", "sample", "strings", "to", "be", "sorted"]
System.print("Unsorted: %(strings)")
Sort.insertion(strings, cmp)
System.print("Sorted : %(strings)")</lang>

{{out}}
<pre>
Unsorted: [Here, are, some, sample, strings, to, be, sorted]
Sorted : [strings, sample, sorted, Here, some, are, be, to]
</pre>


=={{header|zkl}}==
=={{header|zkl}}==