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:
-
a
Stringfirst string to compare
-
b
Stringsecond string to compare
Returns:
-1,0,+1 based on comparing the strings
compareAsStringNoCase
-
a
-
b
Parameters:
-
a
Stringfirst string to compare
-
b
Stringsecond 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:
-
f
Functioncomparator
-
key
String | 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:
-
key
Arraypath to element stored in both a and b
-
a
Objectfirst object to compare
-
b
Objectsecond object to compare
Returns:
values extracted from a and b
flip
-
f
Flip the sort order: sort(Y.Sort.flip(comparator))
Parameters:
-
f
Functionoriginal comparator which takes 2 arguments
Returns:
new comparator that inverts the sort order