Logo

Programming-Idioms

History of Idiom 28 > diff from v89 to v90

Edit summary for version 90 by programming-idioms.org:
Fix dartpad demo link

Version 89

2023-08-17, 12:05:29

Version 90

2023-10-31, 21:23:47

Idiom #28 Sort by a property

Sort the elements of the list (or array-like collection) items in ascending order of x.p, where p is a field of the type Item of the objects in items.

Idiom #28 Sort by a property

Sort the elements of the list (or array-like collection) items in ascending order of x.p, where p is a field of the type Item of the objects in items.

Variables
items,p
Variables
items,p
Code
items.sort((a, b) => Comparable.compare(a.p, b.p));
Code
items.sort((a, b) => Comparable.compare(a.p, b.p));
Demo URL
https://dartpad.dartlang.org/e257952adde1efa570c3
Demo URL
https://dartpad.dev/?id=e257952adde1efa570c3