Array Class
Set of functions that deal with arrays.
Item Index
Methods
- binaryFind static
- binaryIndexOf static
- find static
- indexOf static
- remove static
- unique static
Methods
binaryFind
-
arr
-
compareFcn
Given a function which takes one argument and returns 1, 0, or -1, returns the first element which causes the given function to return 0.
Returns:
the index of the element that causes the given function to return 0, returns -1 if no such element exists
binaryIndexOf
-
arr
-
compareFcn
Given a function which takes one argument and returns 1, 0, or -1, returns the first element which causes the given function to return 0.
Returns:
the index of the element that causes the given function to return 0, returns -1 if no such element exists
find
-
arr
-
predicate
-
scope
Returns the first element in the given array that satisfies the given predicate. Returns null if no element in the given array satisfies the given predicate.
EXAMPLE
var array = [1, 2, 3, 4]
find(array, function(a_number) { return a_number === 2 }); -> 2
find(array, function(a_number) { return a_number === 5 }); -> null
Parameters:
Returns:
first element that satisfies the given predicate; null
if no such element is found
indexOf
-
arr
-
predicate
-
scope
Returns the index of the first element in the given array that satisfies the given predicate. Returns -1 if no element in the given array satisfies the predicate.
Parameters:
Returns:
index of the first element that satisfied the predicate; -1
if no such element is found
remove
-
array
-
obj
-
[predicate]
Removes an item from the specified array.
Parameters:
-
array
ArrayArray to have the item removed from
-
obj
Number | String | Objectcan be either an index of the item to be removed, a String to be removed from the array of strings, or an actual Object to be removed; if obj is an Object, you need to provide a predicate function
-
[predicate]
Function optionala function that takes one argument and returns true if the argument satisfies some condition, and false otherwise.