Sort Class
Utilities for sorting.
Item Index
Methods
- compareAsNumber static
- compareAsString static
- compareAsStringNoCase static
- compareKey static
- drill static
- flip static
Methods
compareAsNumber
-
a -
b
The default behavior for sorting numbers. Provided for cases where one needs to compare object members.
Returns:
-1,0,+1 based on comparing the values
compareAsString
-
a -
b
The default behavior for sorting strings. Provided for cases where one needs to compare object members.
Parameters:
-
aStringfirst string to compare
-
bStringsecond string to compare
Returns:
-1,0,+1 based on comparing the strings
compareAsStringNoCase
-
a -
b
Parameters:
-
aStringfirst string to compare
-
bStringsecond string to compare
Returns:
-1,0,+1 based on comparing the strings when ignoring case
compareKey
-
f -
key
Sort by an object member:
sort(Y.bind(Y.Sort.compareKey, null, Y.Sort.compareAs*, key_or_path))
Key can be an array, to drill deep inside the objects, e.g.,
['foo','bar','baz'] translates to a.foo.bar.baz
Parameters:
-
fFunctioncomparator
-
keyString | Arrayobject key or path to the value which should be compared
Returns:
-1,0,+1 based on comparing the values
drill
-
key -
a -
b
Utility function for extracting the same value from both comparator arguments.
Parameters:
-
keyArraypath to element stored in both a and b
-
aObjectfirst object to compare
-
bObjectsecond object to compare
Returns:
values extracted from a and b
flip
-
f
Flip the sort order: sort(Y.Sort.flip(comparator))
Parameters:
-
fFunctionoriginal comparator which takes 2 arguments
Returns:
new comparator that inverts the sort order
