Logo

Programming-Idioms

History of Idiom 100 > diff from v29 to v30

Edit summary for version 30 by programming-idioms.org:
[JS] List name is items. No need for sample values. +DemoURL

Version 29

2016-12-11, 20:24:08

Version 30

2016-12-11, 20:37:02

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
var lst = [7,4,3,1,2];

lst.sort(function(a,b){return a-b;});

console.log(lst);
Code
items.sort(c);
Demo URL
http://codepen.io/anon/pen/RoYPzy?editors=1111