Logo

Programming-Idioms

History of Idiom 100 > diff from v25 to v26

Edit summary for version 26 by steenslag:
[Ruby] typo

Version 25

2016-10-08, 21:37:56

Version 26

2016-10-08, 21:52:59

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 }
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.
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.