RosettaCodeData/Task/Sort-stability/JavaScript/sort-stability.js
Ingy döt Net 68f8f3e56b all tasks
2013-04-11 01:07:29 -07:00

7 lines
268 B
JavaScript

ary = [["UK", "London"], ["US", "New York"], ["US", "Birmingham"], ["UK", "Birmingham"]]
print(ary);
ary.sort(function(a,b){return (a[1]<b[1] ? -1 : (a[1]>b[1] ? 1 : 0))});
print(ary);
/* a stable sort will output ["US", "Birmingham"] before ["UK", "Birmingham"] */