Provides comparator functions useful for sorting arrays.
_splitAlphaNum
string
Splits a string into an array of alpha character and digit character parts.
string
String
String to split.
Array of alpha parts and digit parts.
Y.ArraySort._splitAlphaNum('abc123def456');
// => ['abc', '123', 'def', '456']
compare
a
b
desc
Comparator function for simple case-insensitive sorting of an array of strings.
-1 when a < b. 0 when a == b. 1 when a > b.
naturalCompare
a
b
[options]
Performs a natural-order comparison of two strings or numbers (or a string and a number). This ensures that a value like 'foo2' will be sorted before 'foo10', whereas a standard ASCII sort would sort 'foo10' first.
0
if the two items are equal, a negative number if a
should be sorted before b, or a positive number if b should be
sorted before a.
var items = ['item10', 'item2', 'item1', 10, '1', 2];
items.sort(Y.ArraySort.naturalCompare);
console.log(items); // => ['1', 2, 10, 'item1', 'item2', 'item10']