minor changes in sortBy

This commit is contained in:
rolux 2012-04-11 22:36:27 +02:00
parent 27d37ea601
commit b28eb7ec51

View file

@ -487,14 +487,15 @@ Ox.range = function() {
[{id: 1, name: '8 Women'}, {id: 0, name: '80 Days'}]
@*/
Ox.sortBy = function(arr, by, fn) {
var length = by.length, values = {};
var values = {};
by = Ox.toArray(by);
fn = fn || {};
by = by.map(function(v) {
return Ox.isString(v) ? {
key: v.replace(/^[\+\-]/, ''),
operator: v[0] == '-' ? '-' : '+'
} : v;
});
fn = fn || {};
by.map(function(v) {
return v.key;
}).forEach(function(key) {
@ -504,7 +505,7 @@ Ox.range = function() {
});
return arr.sort(function(a, b) {
var aValue, bValue, index = 0, key, ret = 0;
while (ret == 0 && index < length) {
while (ret == 0 && index < by.length) {
key = by[index].key;
aValue = values[key][a[key]];
bValue = values[key][b[key]];