fix a bug in sort/sortBy

This commit is contained in:
rolux 2012-06-19 21:29:16 +02:00
parent 5bbce78878
commit 46f2fa516e

View file

@ -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;