Optional parameters: Difference between revisions
Content deleted Content added
m de-omit from Factor since it already has an implementation |
Drkameleon (talk | contribs) Added Arturo implementation |
||
Line 130: | Line 130: | ||
sortTable({sequence:table, reverse:true}) |
sortTable({sequence:table, reverse:true}) |
||
sortTable({sequence:table})</lang> |
sortTable({sequence:table})</lang> |
||
=={{header|Arturo}}== |
|||
<lang rebol> |
|||
sortTable: function [tbl][ |
|||
column: "0" |
|||
reversed?: false |
|||
unless null? c: <= attr 'column -> column: to :string c |
|||
unless null? attr 'reverse -> reversed?: true |
|||
result: new sort.by: column map tbl 'r [ |
|||
to :dictionary flatten combine 0..dec size r r |
|||
] |
|||
if reversed? -> reverse 'result |
|||
return map result 'r -> values r |
|||
] |
|||
printTable: function [tbl, title][ |
|||
print ["==" title] |
|||
loop tbl 'row [ |
|||
print row |
|||
] |
|||
print "" |
|||
] |
|||
lst: [ |
|||
["a", "b", "c"] |
|||
["", "q", "z"] |
|||
["zap", "zip", "Zot"] |
|||
] |
|||
printTable sortTable lst "Default sort" |
|||
printTable sortTable.column:1 lst "Sorting by column=1" |
|||
printTable sortTable.reverse lst "Sorting, reversed" |
|||
printTable sortTable.reverse.column:1 lst "Sorting by column=1, reversed"</lang> |
|||
{{out}} |
|||
<pre>== Default sort |
|||
q z |
|||
a b c |
|||
zap zip Zot |
|||
== Sorting by column=1 |
|||
a b c |
|||
q z |
|||
zap zip Zot |
|||
== Sorting, reversed |
|||
zap zip Zot |
|||
a b c |
|||
q z |
|||
== Sorting by column=1, reversed |
|||
zap zip Zot |
|||
q z |
|||
a b c</pre> |
|||
=={{header|AutoHotkey}}== |
=={{header|AutoHotkey}}== |