From 46f2fa516e6e952b6336903c0c04c0c3a73ca062 Mon Sep 17 00:00:00 2001 From: rolux Date: Tue, 19 Jun 2012 21:29:16 +0200 Subject: [PATCH] fix a bug in sort/sortBy --- source/Ox/js/Array.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/source/Ox/js/Array.js b/source/Ox/js/Array.js index 88b810c6..d6f1d8cc 100644 --- a/source/Ox/js/Array.js +++ b/source/Ox/js/Array.js @@ -572,11 +572,13 @@ Ox.range = function() { var mappedArray = map ? array.map(map) : array, length = 0, sort = {}; // find numbers, and length of longest number array.forEach(function(value, i) { - var match, mappedValue = mappedArray[i]; + var mappedValue = mappedArray[i], matches; if (Ox.isString(mappedValue)) { - match = mappedValue.match(/\d+/g); - if (match && match.length > length) { - length = match.length; + matches = mappedValue.match(/\d+/g); + if (matches) { + length = Ox.max(matches.map(function(match) { + return match.length; + }).concat(length)); } } }); @@ -594,7 +596,7 @@ Ox.range = function() { sort[value] = mappedValue.toLowerCase() .replace(/^\W+/, '') .replace(/\d+/g, function(match) { - return Ox.pad(parseInt(match, 10), length); + return Ox.pad(match, 'left', length, '0'); }); Ox.forEach(['a', 'an', 'the'], function(article) { var length;