@@ -16,43 +16,28 @@ function array_multisort(arr) {
16
16
// bits: HGFE DCBA
17
17
// args: Holds pointer to arguments for reassignment
18
18
19
- var argl = arguments . length ,
20
- sal = 0 ,
21
- flags = {
22
- 'SORT_REGULAR' : 16 ,
23
- 'SORT_NUMERIC' : 17 ,
24
- 'SORT_STRING' : 18 ,
25
- 'SORT_ASC' : 32 ,
26
- 'SORT_DESC' : 40
27
- } ,
28
- sortArrs = [
29
- [ ]
30
- ] ,
31
- sortFlag = [ 0 ] ,
32
- sortKeys = [
33
- [ ]
34
- ] ,
35
- g = 0 ,
36
- i = 0 ,
37
- j = 0 ,
38
- k = '' ,
39
- l = 0 ,
40
- thingsToSort = [ ] ,
41
- vkey = 0 ,
42
- zlast = null ,
43
- args = arguments ,
44
- nLastSort = [ ] ,
45
- lastSort = [ ] ,
46
- lastSorts = [ ] ,
47
- tmpArray = [ ] ,
48
- elIndex = 0 ,
49
- sortDuplicator = function ( a , b ) {
50
- return nLastSort . shift ( ) ;
51
- } ;
19
+ var g , i , j , k , l , sal , vkey , elIndex , lastSorts , tmpArray , zlast ;
52
20
53
- sortFunctions = [
54
- [
21
+ var sortFlag = [ 0 ] ;
22
+ var thingsToSort = [ ] ;
23
+ var nLastSort = [ ] ;
24
+ var lastSort = [ ] ;
25
+ var args = arguments ; // possibly redundant
55
26
27
+ var flags = {
28
+ 'SORT_REGULAR' : 16 ,
29
+ 'SORT_NUMERIC' : 17 ,
30
+ 'SORT_STRING' : 18 ,
31
+ 'SORT_ASC' : 32 ,
32
+ 'SORT_DESC' : 40
33
+ } ;
34
+
35
+ var sortDuplicator = function ( a , b ) {
36
+ return nLastSort . shift ( ) ;
37
+ } ;
38
+
39
+ var sortFunctions = [
40
+ [
56
41
function ( a , b ) {
57
42
lastSort . push ( a > b ? 1 : ( a < b ? - 1 : 0 ) ) ;
58
43
return a > b ? 1 : ( a < b ? - 1 : 0 ) ;
@@ -63,7 +48,6 @@ function array_multisort(arr) {
63
48
}
64
49
] ,
65
50
[
66
-
67
51
function ( a , b ) {
68
52
lastSort . push ( a - b ) ;
69
53
return a - b ;
@@ -74,7 +58,6 @@ function array_multisort(arr) {
74
58
}
75
59
] ,
76
60
[
77
-
78
61
function ( a , b ) {
79
62
lastSort . push ( ( a + '' ) > ( b + '' ) ? 1 : ( ( a + '' ) < ( b + '' ) ? - 1 : 0 ) ) ;
80
63
return ( a + '' ) > ( b + '' ) ? 1 : ( ( a + '' ) < ( b + '' ) ? - 1 : 0 ) ;
@@ -86,6 +69,14 @@ function array_multisort(arr) {
86
69
]
87
70
] ;
88
71
72
+ var sortArrs = [
73
+ [ ]
74
+ ] ;
75
+
76
+ var sortKeys = [
77
+ [ ]
78
+ ] ;
79
+
89
80
// Store first argument into sortArrs and sortKeys if an Object.
90
81
// First Argument should be either a Javascript Array or an Object, otherwise function would return FALSE like in PHP
91
82
if ( Object . prototype . toString . call ( arr ) === '[object Array]' ) {
@@ -104,10 +95,11 @@ function array_multisort(arr) {
104
95
// arrMainLength: Holds the length of the first array. All other arrays must be of equal length, otherwise function would return FALSE like in PHP
105
96
//
106
97
// sortComponents: Holds 2 indexes per every section of the array that can be sorted. As this is the start, the whole array can be sorted.
107
- var arrMainLength = sortArrs [ 0 ] . length ,
108
- sortComponents = [ 0 , arrMainLength ] ;
98
+ var arrMainLength = sortArrs [ 0 ] . length ;
99
+ var sortComponents = [ 0 , arrMainLength ] ;
109
100
110
101
// Loop through all other arguments, checking lengths and sort flags of arrays and adding them to the above variables.
102
+ var argl = arguments . length ;
111
103
for ( j = 1 ; j < argl ; j ++ ) {
112
104
if ( Object . prototype . toString . call ( arguments [ j ] ) === '[object Array]' ) {
113
105
sortArrs [ j ] = arguments [ j ] ;
@@ -130,7 +122,8 @@ function array_multisort(arr) {
130
122
}
131
123
} else if ( typeof arguments [ j ] === 'string' ) {
132
124
var lFlag = sortFlag . pop ( ) ;
133
- if ( typeof flags [ arguments [ j ] ] === 'undefined' || ( ( ( ( flags [ arguments [ j ] ] ) >>> 4 ) & ( lFlag >>> 4 ) ) > 0 ) ) { // Keep extra parentheses around latter flags check to avoid minimization leading to CDATA closer
125
+ // Keep extra parentheses around latter flags check to avoid minimization leading to CDATA closer
126
+ if ( typeof flags [ arguments [ j ] ] === 'undefined' || ( ( ( ( flags [ arguments [ j ] ] ) >>> 4 ) & ( lFlag >>> 4 ) ) > 0 ) ) {
134
127
return false ;
135
128
}
136
129
sortFlag . push ( lFlag + flags [ arguments [ j ] ] ) ;
@@ -152,7 +145,7 @@ function array_multisort(arr) {
152
145
nLastSort = [ ] ;
153
146
lastSort = [ ] ;
154
147
155
- // If ther are no sortComponents, then no more sorting is neeeded. Copy the array back to the argument.
148
+ // If there are no sortComponents, then no more sorting is neeeded. Copy the array back to the argument.
156
149
if ( sortComponents . length === 0 ) {
157
150
if ( Object . prototype . toString . call ( arguments [ i ] ) === '[object Array]' ) {
158
151
args [ i ] = sortArrs [ i ] ;
0 commit comments