Optional parameters: Difference between revisions
Content added Content deleted
(Nimrod -> Nim) |
m (Added Sidef language) |
||
Line 1,759: | Line 1,759: | ||
println(sortTable(data, ((a, b)=> b.size<a.size))) |
println(sortTable(data, ((a, b)=> b.size<a.size))) |
||
//-> List(List(zap, zip, Zot), List(a, b, c), List(, q, z))</lang> |
//-> List(List(zap, zip, Zot), List(a, b, c), List(, q, z))</lang> |
||
=={{header|Sidef}}== |
|||
<lang ruby>func table_sort(table, ordering: '<=>', column: 0, reverse: false) { |
|||
if (reverse) { |
|||
table.sort {|a,b| b[column].$ordering(a[column])} |
|||
} else { |
|||
table.sort {|a,b| a[column].$ordering(b[column])} |
|||
} |
|||
} |
|||
# Quick example: |
|||
var table = [ |
|||
["Ottowa", "Canada"], |
|||
["Washington", "USA"], |
|||
["Mexico City", "Mexico"], |
|||
]; |
|||
say table_sort(table, column: 1).dump;</lang> |
|||
{{out}} |
|||
<pre>[["Ottowa", "Canada"], ["Mexico City", "Mexico"], ["Washington", "USA"]]</pre> |
|||
=={{header|Slate}}== |
=={{header|Slate}}== |