Logo

Programming-Idioms

History of Idiom 100 > diff from v24 to v25

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

Version 24

2016-06-02, 03:38:05

Version 25

2016-10-08, 21:37:56

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.

Code
items = = [7,4,3,1,2]
items.sort!{|a,b| a-b }
Comments bubble
sort! sorts in_place (sort would leave items unmodified). Comparator c is not idiomatic, items is sorted according to the code in the block.