Logo

Programming-Idioms

History of Idiom 100 > diff from v41 to v42

Edit summary for version 42 by programming-idioms.org:
[Ruby] No need for sample values

Version 41

2017-07-14, 15:05:13

Version 42

2017-07-14, 15:06:01

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)
Code
items.sort!(&c)
Comments bubble
Idiomatic would be using a block instead of a named procedure (c).
Comments bubble
Idiomatic would be using a block instead of named procedure c.