Array~algorithms Class
Useful algorithms not provided by browsers.
Item Index
Methods
- binarySearch static
- compareStringsCaseInsensitive static
- compareStringsCaseSensitive static
- quickSort static
- swap static
Methods
binarySearch
(
Int
static
-
list
-
target
-
[compare=Y.Array.compareStringsCaseSensitive]
Binary search.
Parameters:
-
list
Arraythe list to search (sorted on the compare function)
-
target
Mixedthe object to search for
-
[compare=Y.Array.compareStringsCaseSensitive]
Function optionalthe comparison function
Returns:
Int:
index of matched item or -1 if no match
compareStringsCaseInsensitive
(
static
-
s1
-
s2
A -1,0,+1 comparator for case-insensitive string comparison.
Parameters:
-
s1
Stringfirst string
-
s2
Stringsecond string
Returns:
-1 if s1<s2, 0 if s1==s2, +1 if s1>s2
compareStringsCaseSensitive
(
static
-
s1
-
s2
A -1,0,+1 comparator for case-sensitive string comparison.
Parameters:
-
s1
Stringfirst string
-
s2
Stringsecond string
Returns:
-1 if s1<s2, 0 if s1==s2, +1 if s1>s2
quickSort
(
static
-
list
-
compare=Y.Array.compareStringsCaseSensitive
Quick sort the given list.
Parameters:
-
list
Arraythe list to search (sorted on the compare function)
-
compare=Y.Array.compareStringsCaseSensitive
Functionthe comparison function
swap
(
static
-
list
-
i
-
j
Swaps two elements.
Parameters:
-
list
Arraythe list on which to operate
-
i
Intfirst index
-
j
Intsecond index