fix sort value for '[article] [number or quoted string]', add test
This commit is contained in:
parent
0de55efb96
commit
b5a2e80878
1 changed files with 14 additions and 7 deletions
|
@ -583,6 +583,13 @@ Ox.range = function() {
|
||||||
// make lowercase, remove leading non-word characters,
|
// make lowercase, remove leading non-word characters,
|
||||||
// pad numbers and move leading articles to the end
|
// pad numbers and move leading articles to the end
|
||||||
array.forEach(function(value, i) {
|
array.forEach(function(value, i) {
|
||||||
|
function pad(value) {
|
||||||
|
return value
|
||||||
|
.replace(/^\W+/, '')
|
||||||
|
.replace(/\d+/g, function(match) {
|
||||||
|
return Ox.pad(match, 'left', length, '0');
|
||||||
|
});
|
||||||
|
}
|
||||||
var mappedValue = mappedArray[i];
|
var mappedValue = mappedArray[i];
|
||||||
if (
|
if (
|
||||||
Ox.isEmpty(mappedValue)
|
Ox.isEmpty(mappedValue)
|
||||||
|
@ -591,17 +598,15 @@ Ox.range = function() {
|
||||||
) {
|
) {
|
||||||
sort[value] = null;
|
sort[value] = null;
|
||||||
} else if (Ox.isString(mappedValue)) {
|
} else if (Ox.isString(mappedValue)) {
|
||||||
sort[value] = mappedValue.toLowerCase()
|
sort[value] = pad(mappedValue.toLowerCase());
|
||||||
.replace(/^\W+/, '')
|
|
||||||
.replace(/\d+/g, function(match) {
|
|
||||||
return Ox.pad(match, 'left', length, '0');
|
|
||||||
});
|
|
||||||
Ox.forEach(['a', 'an', 'the'], function(article) {
|
Ox.forEach(['a', 'an', 'the'], function(article) {
|
||||||
var length;
|
var length;
|
||||||
if (new RegExp('^' + article + ' ').test(sort[value])) {
|
if (new RegExp('^' + article + ' ').test(sort[value])) {
|
||||||
length = article.length;
|
length = article.length;
|
||||||
sort[value] = sort[value].slice(length + 1) + ', '
|
sort[value] = pad(
|
||||||
+ sort[value].slice(0, length);
|
sort[value].slice(length + 1) + ', '
|
||||||
|
+ sort[value].slice(0, length)
|
||||||
|
);
|
||||||
return false; // break
|
return false; // break
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -626,6 +631,8 @@ Ox.range = function() {
|
||||||
['In 9 Minutes Around the World', 'In 80 Days Around the World']
|
['In 9 Minutes Around the World', 'In 80 Days Around the World']
|
||||||
> Ox.sort(['Man', 'A Plan', 'The Canal'])
|
> Ox.sort(['Man', 'A Plan', 'The Canal'])
|
||||||
['The Canal', 'Man', 'A Plan']
|
['The Canal', 'Man', 'A Plan']
|
||||||
|
> Ox.sort(['The 9', 'The 10', 'An A', 'A "B"'])
|
||||||
|
['The 9', 'The 10', 'An A', 'A "B"']
|
||||||
@*/
|
@*/
|
||||||
Ox.sort = function(array, map) {
|
Ox.sort = function(array, map) {
|
||||||
var values = getSortValues(map ? array.map(map) : array);
|
var values = getSortValues(map ? array.map(map) : array);
|
||||||
|
|
Loading…
Reference in a new issue