Logo

Programming-Idioms

History of Idiom 100 > diff from v39 to v40

Edit summary for version 40 by steenslag:
New Ruby implementation by user [steenslag]

Version 39

2017-06-03, 07:50:48

Version 40

2017-07-12, 20:41:08

Idiom #100 Sort by a comparator

Sort elements of array-like collection items, using a comparator c.

Idiom #100 Sort by a comparator

Sort elements of array-like collection items, using a comparator c.

Extra Keywords
list
Extra Keywords
list
Code
items = [7,4,3,1,2]
c = ->(a,b){a-b}
items.sort!(&c)
Comments bubble
Idiomatic would be using a block instead of a named procedure (c).