Logo

Programming-Idioms

History of Idiom 100 > diff from v40 to v41

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

Version 40

2017-07-12, 20:41:08

Version 41

2017-07-14, 15:05:13

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]
items.sort!{|a,b| a-b }
Code
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
Demo URL
https://repl.it/EWdW/0