Ox.sort: handle thousand separators

This commit is contained in:
rolux 2013-02-03 12:44:40 +05:30
parent fc8368cc9f
commit 36bb42e7bd

View file

@ -625,8 +625,9 @@ Ox.range = function() {
return false; // break
}
});
// pad numbers
sortValue = sortValue.replace(/\d+/g, function(match) {
// remove thousand separators and pad numbers
sortValue = sortValue.replace(/(\d),(?=(\d{3}))/g, '$1')
.replace(/\d+/g, function(match) {
return Ox.pad(match, 'left', 64, '0');
});
}
@ -647,6 +648,8 @@ Ox.range = function() {
[{id: 1, name: '8 Women'}, {id: 0, name: '80 Days'}]
> Ox.sort(['In 80 Days Around the World', 'In 9 Minutes Around the World'])
['In 9 Minutes Around the World', 'In 80 Days Around the World']
> Ox.sort(['80 Days', '20,000 Leagues'])
['80 Days', '20,000 Leagues']
> Ox.sort(['Man', 'A Plan', 'The Canal'])
['The Canal', 'Man', 'A Plan']
> Ox.sort(['The 9', 'The 10', 'An A', 'A "B"'])