Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
16
Task/Optional-parameters/Ruby/optional-parameters-2.rb
Normal file
16
Task/Optional-parameters/Ruby/optional-parameters-2.rb
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
def table_sort(table, ordering: :<=>, column: 0, reverse: false)
|
||||
p = ordering.to_proc
|
||||
if reverse
|
||||
table.sort {|a, b| p.(b[column], a[column])}
|
||||
else
|
||||
table.sort {|a, b| p.(a[column], b[column])}
|
||||
end
|
||||
end
|
||||
|
||||
# Quick example:
|
||||
table = [
|
||||
["Ottowa", "Canada"],
|
||||
["Washington", "USA"],
|
||||
["Mexico City", "Mexico"],
|
||||
]
|
||||
p table_sort(table, column: 1)
|
||||
Loading…
Add table
Add a link
Reference in a new issue