/
arraysort-debug.js
65 lines (53 loc) · 1.34 KB
/
arraysort-debug.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
YUI.add('arraysort', function(Y) {
/**
Provides a case-insenstive comparator which can be used for array sorting.
@module arraysort
*/
var LANG = Y.Lang,
ISVALUE = LANG.isValue,
ISSTRING = LANG.isString;
/**
Provides a case-insenstive comparator which can be used for array sorting.
@class ArraySort
*/
Y.ArraySort = {
/**
Comparator function for simple case-insensitive sorting of an array of
strings.
@method compare
@param a {Object} First sort argument.
@param b {Object} Second sort argument.
@param desc {Boolean} `true` if sort direction is descending, `false` if
sort direction is ascending.
@return {Boolean} -1 when a < b. 0 when a == b. 1 when a > b.
*/
compare: function(a, b, desc) {
if(!ISVALUE(a)) {
if(!ISVALUE(b)) {
return 0;
}
else {
return 1;
}
}
else if(!ISVALUE(b)) {
return -1;
}
if(ISSTRING(a)) {
a = a.toLowerCase();
}
if(ISSTRING(b)) {
b = b.toLowerCase();
}
if(a < b) {
return (desc) ? 1 : -1;
}
else if (a > b) {
return (desc) ? -1 : 1;
}
else {
return 0;
}
}
};
}, '@VERSION@' ,{requires:['yui-base']});