Logo

Programming-Idioms

History of Idiom 100 > diff from v26 to v27

Edit summary for version 27 by programming-idioms.org:
[Ruby] +DemoURL

Version 26

2016-10-08, 21:52:59

Version 27

2016-11-13, 14:59:55

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.
Demo URL
https://repl.it/EWdW/0