From 36bb42e7bd97a5848e4cdc13f119b4d6c02a6c0e Mon Sep 17 00:00:00 2001 From: rolux Date: Sun, 3 Feb 2013 12:44:40 +0530 Subject: [PATCH] Ox.sort: handle thousand separators --- source/Ox/js/Array.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/source/Ox/js/Array.js b/source/Ox/js/Array.js index ec21a84d..41b6ce86 100644 --- a/source/Ox/js/Array.js +++ b/source/Ox/js/Array.js @@ -625,10 +625,11 @@ Ox.range = function() { return false; // break } }); - // pad numbers - sortValue = sortValue.replace(/\d+/g, function(match) { - return Ox.pad(match, 'left', 64, '0'); - }); + // 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'); + }); } return sortValue; }, {key: function(args) { @@ -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"'])