You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
337 lines
82 KiB
337 lines
82 KiB
<!DOCTYPE html><meta charset="UTF-8"><meta http-equiv="Content-Language" content="en" /><title>goog.array</title><link href="dossier.css" rel="stylesheet" type="text/css"><div id="main-wrapper"><input type="checkbox" id="sidenav-toggle" /><main><header><h1>Namespace goog.array</h1><a class="source" href="source/lib/goog/array/array.js.src.html#l21">code »</a></header><section></section><div id="visibility-controls"><b>Show:</b><label for="show-public"><span><input type="checkbox" id="show-public" checked/></span>Public</label><label for="show-protected"><span><input type="checkbox" id="show-protected"/></span>Protected</label><label for="show-private"><span><input type="checkbox" id="show-private"/></span>Private</label></div><section id="typedefs"><h2>Type Definitions</h2><div class="wrap-details public"><div><details><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l56">code »</a><a class="member" name="goog.array.ArrayLike">goog.array.ArrayLike</a> : <code class="type">(<a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>|<a href="http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core.html#ID-536297177">NodeList</a>|<a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Functions_and_function_scope/arguments">Arguments</a>|{length: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>})</code></div><div>No description.</div></summary></details></div></div></section><section id="static-functions"><h2>Global Functions</h2><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l1292">code »</a><code class="type"><VALUE></code> <span class="member"><a name="goog.array.binaryInsert">goog.array.binaryInsert</a> <span class="args">( array, value, opt_compareFn )</span> ⇒ <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a></code></span></div><p>Inserts a value into a sorted array. The array is not modified if the
|
|
value is already present.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>array: <code class="type">(<a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>.<VALUE>|<a href="namespace_goog_array.html#goog.array.ArrayLike">goog.array.ArrayLike</a>)</code><dd>The array to modify.<dt>value: <code class="type">VALUE</code><dd>The object to insert.<dt>opt_compareFn: <code class="type">function(VALUE, VALUE): <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>=</code><dd>Optional comparison
|
|
function by which the array is ordered. Should take 2 arguments to
|
|
compare, and return a negative number, zero, or a positive number
|
|
depending on whether the first argument is less than, equal to, or
|
|
greater than the second.</dl><tr><th>Returns<tr><td><dl>True if an element was inserted.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l1314">code »</a><code class="type"><VALUE></code> <span class="member"><a name="goog.array.binaryRemove">goog.array.binaryRemove</a> <span class="args">( array, value, opt_compareFn )</span> ⇒ <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a></code></span></div><p>Removes a value from a sorted array.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>array: <code class="type">(!<a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>.<VALUE>|!<a href="namespace_goog_array.html#goog.array.ArrayLike">goog.array.ArrayLike</a>)</code><dd>The array to modify.<dt>value: <code class="type">VALUE</code><dd>The object to remove.<dt>opt_compareFn: <code class="type">function(VALUE, VALUE): <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>=</code><dd>Optional comparison
|
|
function by which the array is ordered. Should take 2 arguments to
|
|
compare, and return a negative number, zero, or a positive number
|
|
depending on whether the first argument is less than, equal to, or
|
|
greater than the second.</dl><tr><th>Returns<tr><td><dl>True if an element was removed.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l999">code »</a><code class="type"><TARGET, VALUE></code> <span class="member"><a name="goog.array.binarySearch">goog.array.binarySearch</a> <span class="args">( arr, target, opt_compareFn )</span> ⇒ <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></code></span></div><p>Searches the specified array for the specified target using the binary
|
|
search algorithm. If no opt_compareFn is specified, elements are compared
|
|
using <code>goog.array.defaultCompare</code>, which compares the elements
|
|
using the built in < and > operators. This will produce the expected
|
|
behavior for homogeneous arrays of String(s) and Number(s). The array
|
|
specified <b>must</b> be sorted in ascending order (as defined by the
|
|
comparison function). If the array is not sorted, results are undefined.
|
|
If the array contains multiple instances of the specified target value, any
|
|
of these instances may be found.
|
|
|
|
Runtime: O(log n)</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>arr: <code class="type">(<a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>.<VALUE>|<a href="namespace_goog_array.html#goog.array.ArrayLike">goog.array.ArrayLike</a>)</code><dd>The array to be searched.<dt>target: <code class="type">TARGET</code><dd>The sought value.<dt>opt_compareFn: <code class="type">function(TARGET, VALUE): <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>=</code><dd>Optional comparison
|
|
function by which the array is ordered. Should take 2 arguments to
|
|
compare, and return a negative number, zero, or a positive number
|
|
depending on whether the first argument is less than, equal to, or
|
|
greater than the second.</dl><tr><th>Returns<tr><td><dl>Lowest index of the target value if found, otherwise
|
|
(-(insertion point) - 1). The insertion point is where the value should
|
|
be inserted into arr to preserve the sorted property. Return value >= 0
|
|
iff target is found.</dl></table></div></details></div></div><div class="wrap-details private"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l1066">code »</a><code class="type"><THIS, VALUE, TARGET></code> <span class="member"><a name="goog.array.binarySearch_">goog.array.binarySearch_</a> <span class="args">( arr, compareFn, isEvaluator, opt_target, opt_selfObj )</span> ⇒ <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></code></span></div><p>Implementation of a binary search algorithm which knows how to use both
|
|
comparison functions and evaluators. If an evaluator is provided, will call
|
|
the evaluator with the given optional data object, conforming to the
|
|
interface defined in binarySelect. Otherwise, if a comparison function is
|
|
provided, will call the comparison function against the given data object.
|
|
|
|
This implementation purposefully does not use goog.bind or goog.partial for
|
|
performance reasons.
|
|
|
|
Runtime: O(log n)</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>arr: <code class="type">(<a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>.<VALUE>|<a href="namespace_goog_array.html#goog.array.ArrayLike">goog.array.ArrayLike</a>)</code><dd>The array to be searched.<dt>compareFn: <code class="type">(function(TARGET, VALUE): <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>|function(this: THIS, VALUE, <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>, ?): <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>)</code><dd>Either an
|
|
evaluator or a comparison function, as defined by binarySearch
|
|
and binarySelect above.<dt>isEvaluator: <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a></code><dd>Whether the function is an evaluator or a
|
|
comparison function.<dt>opt_target: <code class="type">TARGET=</code><dd>If the function is a comparison function, then
|
|
this is the target to binary search for.<dt>opt_selfObj: <code class="type">THIS=</code><dd>If the function is an evaluator, this is an
|
|
optional this object for the evaluator.</dl><tr><th>Returns<tr><td><dl>Lowest index of the target value if found, otherwise
|
|
(-(insertion point) - 1). The insertion point is where the value should
|
|
be inserted into arr to preserve the sorted property. Return value >= 0
|
|
iff target is found.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l1030">code »</a><code class="type"><THIS, VALUE></code> <span class="member"><a name="goog.array.binarySelect">goog.array.binarySelect</a> <span class="args">( arr, evaluator, opt_obj )</span> ⇒ <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></code></span></div><p>Selects an index in the specified array using the binary search algorithm.
|
|
The evaluator receives an element and determines whether the desired index
|
|
is before, at, or after it. The evaluator must be consistent (formally,
|
|
goog.array.map(goog.array.map(arr, evaluator, opt_obj), goog.math.sign)
|
|
must be monotonically non-increasing).
|
|
|
|
Runtime: O(log n)</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>arr: <code class="type">(<a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>.<VALUE>|<a href="namespace_goog_array.html#goog.array.ArrayLike">goog.array.ArrayLike</a>)</code><dd>The array to be searched.<dt>evaluator: <code class="type">function(this: THIS, VALUE, <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>, ?): <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></code><dd>Evaluator function that receives 3 arguments (the element, the index and
|
|
the array). Should return a negative number, zero, or a positive number
|
|
depending on whether the desired index is before, at, or after the
|
|
element passed to it.<dt>opt_obj: <code class="type">THIS=</code><dd>The object to be used as the value of 'this'
|
|
within evaluator.</dl><tr><th>Returns<tr><td><dl>Index of the leftmost element matched by the evaluator, if
|
|
such exists; otherwise (-(insertion point) - 1). The insertion point is
|
|
the index of the first element for which the evaluator returns negative,
|
|
or arr.length if no such element exists. The return value is non-negative
|
|
iff a match is found.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l1334">code »</a><code class="type"><T, S></code> <span class="member"><a name="goog.array.bucket">goog.array.bucket</a> <span class="args">( array, sorter, opt_obj )</span> ⇒ <code class="type">!<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a></code></span></div><p>Splits an array into disjoint buckets according to a splitting function.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>array: <code class="type"><a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>.<T></code><dd>The array.<dt>sorter: <code class="type">function(this: S, T, <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>, <a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>.<T>): ?</code><dd>Function to call for
|
|
every element. This takes 3 arguments (the element, the index and the
|
|
array) and must return a valid object key (a string, number, etc), or
|
|
undefined, if that object should not be placed in a bucket.<dt>opt_obj: <code class="type">S=</code><dd>The object to be used as the value of 'this' within
|
|
sorter.</dl><tr><th>Returns<tr><td><dl>An object, with keys being all of the unique return values
|
|
of sorter, and values being arrays containing the items for
|
|
which the splitter returned that key.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l623">code »</a><span class="member"><a name="goog.array.clear">goog.array.clear</a> <span class="args">( arr )</span></span></div><p>Clears the array.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>arr: <code class="type"><a href="namespace_goog_array.html#goog.array.ArrayLike">goog.array.ArrayLike</a></code><dd>Array or array like object to clear.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l826">code »</a><code class="type"><T></code> <span class="member"><a name="goog.array.clone">goog.array.clone</a> <span class="args">( arr )</span> ⇒ <code class="type">!<a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>.<T></code></span></div><p>Does a shallow copy of an array.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>arr: <code class="type">(<a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>.<T>|<a href="namespace_goog_array.html#goog.array.ArrayLike">goog.array.ArrayLike</a>)</code><dd>Array or array-like object to
|
|
clone.</dl><tr><th>Returns<tr><td><dl>Clone of the input array.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l1241">code »</a><code class="type"><VALUE></code> <span class="member"><a name="goog.array.compare3">goog.array.compare3</a> <span class="args">( arr1, arr2, opt_compareFn )</span> ⇒ <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></code></span></div><p>3-way array compare function.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>arr1: <code class="type">(!<a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>.<VALUE>|!<a href="namespace_goog_array.html#goog.array.ArrayLike">goog.array.ArrayLike</a>)</code><dd>The first array to
|
|
compare.<dt>arr2: <code class="type">(!<a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>.<VALUE>|!<a href="namespace_goog_array.html#goog.array.ArrayLike">goog.array.ArrayLike</a>)</code><dd>The second array to
|
|
compare.<dt>opt_compareFn: <code class="type">function(VALUE, VALUE): <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>=</code><dd>Optional comparison
|
|
function by which the array is to be ordered. Should take 2 arguments to
|
|
compare, and return a negative number, zero, or a positive number
|
|
depending on whether the first argument is less than, equal to, or
|
|
greater than the second.</dl><tr><th>Returns<tr><td><dl>Negative number, zero, or a positive number depending on
|
|
whether the first argument is less than, equal to, or greater than the
|
|
second.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l774">code »</a><span class="member"><a name="goog.array.concat">goog.array.concat</a> <span class="args">( var_args )</span> ⇒ <code class="type">!<a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a></code></span></div><p>Returns a new array that is the result of joining the arguments. If arrays
|
|
are passed then their items are added, however, if non-arrays are passed they
|
|
will be added to the return array as is.
|
|
|
|
Note that ArrayLike objects will be added as is, rather than having their
|
|
items added.
|
|
|
|
goog.array.concat([1, 2], [3, 4]) -> [1, 2, 3, 4]
|
|
goog.array.concat(0, [1, 2]) -> [0, 1, 2]
|
|
goog.array.concat([1, 2], null) -> [1, 2, null]
|
|
|
|
There is bug in all current versions of IE (6, 7 and 8) where arrays created
|
|
in an iframe become corrupted soon (not immediately) after the iframe is
|
|
destroyed. This is common if loading data via goog.net.IframeIo, for example.
|
|
This corruption only affects the concat method which will start throwing
|
|
Catastrophic Errors (#-2147418113).
|
|
|
|
See http://endoflow.com/scratch/corrupted-arrays.html for a test case.
|
|
|
|
Internally goog.array should use this, so that all methods will continue to
|
|
work on these broken array objects.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>var_args: <code class="type">...*</code><dd>Items to concatenate. Arrays will have each item
|
|
added, while primitives and objects will be added as is.</dl><tr><th>Returns<tr><td><dl>The new resultant array.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l604">code »</a><span class="member"><a name="goog.array.contains">goog.array.contains</a> <span class="args">( arr, obj )</span> ⇒ <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a></code></span></div><p>Whether the array contains the given object.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>arr: <code class="type"><a href="namespace_goog_array.html#goog.array.ArrayLike">goog.array.ArrayLike</a></code><dd>The array to test for the presence of the
|
|
element.<dt>obj: <code class="type">*</code><dd>The object for which to test.</dl><tr><th>Returns<tr><td><dl>true if obj is present.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l495">code »</a><code class="type"><T, S></code> <span class="member"><a name="goog.array.count">goog.array.count</a> <span class="args">( arr, f, opt_obj )</span> ⇒ <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></code></span></div><p>Counts the array elements that fulfill the predicate, i.e. for which the
|
|
callback function returns true. Skips holes in the array.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>arr: <code class="type">!(<a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>.<T>|<a href="namespace_goog_array.html#goog.array.ArrayLike">goog.array.ArrayLike</a>)</code><dd>Array or array like object
|
|
over which to iterate.<dt>f: <code class="type">function(this: S, T, <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>, ?): <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a></code><dd>The function to call for
|
|
every element. Takes 3 arguments (the element, the index and the array).<dt>opt_obj: <code class="type">S=</code><dd>The object to be used as the value of 'this' within f.</dl><tr><th>Returns<tr><td><dl>The number of the matching elements.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l1263">code »</a><code class="type"><VALUE></code> <span class="member"><a name="goog.array.defaultCompare">goog.array.defaultCompare</a> <span class="args">( a, b )</span> ⇒ <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></code></span></div><p>Compares its two arguments for order, using the built in < and >
|
|
operators.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>a: <code class="type">VALUE</code><dd>The first object to be compared.<dt>b: <code class="type">VALUE</code><dd>The second object to be compared.</dl><tr><th>Returns<tr><td><dl>A negative number, zero, or a positive number as the first
|
|
argument is less than, equal to, or greater than the second.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l1274">code »</a><span class="member"><a name="goog.array.defaultCompareEquality">goog.array.defaultCompareEquality</a> <span class="args">( a, b )</span> ⇒ <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a></code></span></div><p>Compares its two arguments for equality, using the built in === operator.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>a: <code class="type">*</code><dd>The first object to compare.<dt>b: <code class="type">*</code><dd>The second object to compare.</dl><tr><th>Returns<tr><td><dl>True if the two arguments are equal, false otherwise.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l1209">code »</a><span class="member"><a name="goog.array.equals">goog.array.equals</a> <span class="args">( arr1, arr2, opt_equalsFn )</span> ⇒ <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a></code></span></div><p>Compares two arrays for equality. Two arrays are considered equal if they
|
|
have the same length and their corresponding elements are equal according to
|
|
the comparison function.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>arr1: <code class="type"><a href="namespace_goog_array.html#goog.array.ArrayLike">goog.array.ArrayLike</a></code><dd>The first array to compare.<dt>arr2: <code class="type"><a href="namespace_goog_array.html#goog.array.ArrayLike">goog.array.ArrayLike</a></code><dd>The second array to compare.<dt>opt_equalsFn: <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function">Function</a>=</code><dd>Optional comparison function.
|
|
Should take 2 arguments to compare, and return true if the arguments
|
|
are equal. Defaults to <code class="type"><a href="namespace_goog_array.html#goog.array.defaultCompareEquality">goog.array.defaultCompareEquality</a></code> which
|
|
compares the elements using the built-in '===' operator.</dl><tr><th>Returns<tr><td><dl>Whether the two arrays are equal.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l463">code »</a><code class="type"><T, S></code> <span class="member"><a name="goog.array.every">goog.array.every</a> <span class="args">( arr, f, opt_obj )</span> ⇒ <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a></code></span></div><p>Call f for each element of an array. If all calls return true, every()
|
|
returns true. If any call returns false, every() returns false and
|
|
does not continue to check the remaining elements.
|
|
|
|
See <code class="type"><a class="unresolved-link">http://tinyurl.com/developer-mozilla-org-array-every</a></code></summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>arr: <code class="type">(<a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>.<T>|<a href="namespace_goog_array.html#goog.array.ArrayLike">goog.array.ArrayLike</a>)</code><dd>Array or array
|
|
like object over which to iterate.<dt>f: <code class="type">?function(this: S, T, <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>, ?): <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a></code><dd>The function to call for
|
|
for every element. This function takes 3 arguments (the element, the
|
|
index and the array) and should return a boolean.<dt>opt_obj: <code class="type">S=</code><dd>The object to be used as the value of 'this'
|
|
within f.</dl><tr><th>Returns<tr><td><dl>false if any element fails the test.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l845">code »</a><code class="type"><VALUE></code> <span class="member"><a name="goog.array.extend">goog.array.extend</a> <span class="args">( arr1, var_args )</span></span></div><p>Extends an array with another array, element, or "array like" object.
|
|
This function operates 'in-place', it does not create a new Array.
|
|
|
|
Example:
|
|
var a = [];
|
|
goog.array.extend(a, [0, 1]);
|
|
a; // [0, 1]
|
|
goog.array.extend(a, 2);
|
|
a; // [0, 1, 2]</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>arr1: <code class="type"><a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>.<VALUE></code><dd>The array to modify.<dt>var_args: <code class="type">...(<a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>.<VALUE>|VALUE)</code><dd>The elements or arrays of elements
|
|
to add to arr1.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l259">code »</a><code class="type"><T, S></code> <span class="member"><a name="goog.array.filter">goog.array.filter</a> <span class="args">( arr, f, opt_obj )</span> ⇒ <code class="type">!<a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>.<T></code></span></div><p>Calls a function for each element in an array, and if the function returns
|
|
true adds the element to a new array.
|
|
|
|
See <code class="type"><a class="unresolved-link">http://tinyurl.com/developer-mozilla-org-array-filter</a></code></summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>arr: <code class="type">(<a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>.<T>|<a href="namespace_goog_array.html#goog.array.ArrayLike">goog.array.ArrayLike</a>)</code><dd>Array or array
|
|
like object over which to iterate.<dt>f: <code class="type">?function(this: S, T, <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>, ?): <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a></code><dd>The function to call for
|
|
every element. This function
|
|
takes 3 arguments (the element, the index and the array) and must
|
|
return a Boolean. If the return value is true the element is added to the
|
|
result array. If it is false the element is not included.<dt>opt_obj: <code class="type">S=</code><dd>The object to be used as the value of 'this'
|
|
within f.</dl><tr><th>Returns<tr><td><dl>a new array in which only elements that passed the test
|
|
are present.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l519">code »</a><code class="type"><T, S></code> <span class="member"><a name="goog.array.find">goog.array.find</a> <span class="args">( arr, f, opt_obj )</span> ⇒ <code class="type">?T</code></span></div><p>Search an array for the first element that satisfies a given condition and
|
|
return that element.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>arr: <code class="type">(<a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>.<T>|<a href="namespace_goog_array.html#goog.array.ArrayLike">goog.array.ArrayLike</a>)</code><dd>Array or array
|
|
like object over which to iterate.<dt>f: <code class="type">?function(this: S, T, <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>, ?): <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a></code><dd>The function to call
|
|
for every element. This function takes 3 arguments (the element, the
|
|
index and the array) and should return a boolean.<dt>opt_obj: <code class="type">S=</code><dd>An optional "this" context for the function.</dl><tr><th>Returns<tr><td><dl>The first array element that passes the test, or null if no
|
|
element is found.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l539">code »</a><code class="type"><T, S></code> <span class="member"><a name="goog.array.findIndex">goog.array.findIndex</a> <span class="args">( arr, f, opt_obj )</span> ⇒ <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></code></span></div><p>Search an array for the first element that satisfies a given condition and
|
|
return its index.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>arr: <code class="type">(<a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>.<T>|<a href="namespace_goog_array.html#goog.array.ArrayLike">goog.array.ArrayLike</a>)</code><dd>Array or array
|
|
like object over which to iterate.<dt>f: <code class="type">?function(this: S, T, <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>, ?): <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a></code><dd>The function to call for
|
|
every element. This function
|
|
takes 3 arguments (the element, the index and the array) and should
|
|
return a boolean.<dt>opt_obj: <code class="type">S=</code><dd>An optional "this" context for the function.</dl><tr><th>Returns<tr><td><dl>The index of the first array element that passes the test,
|
|
or -1 if no element is found.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l585">code »</a><code class="type"><T, S></code> <span class="member"><a name="goog.array.findIndexRight">goog.array.findIndexRight</a> <span class="args">( arr, f, opt_obj )</span> ⇒ <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></code></span></div><p>Search an array (in reverse order) for the last element that satisfies a
|
|
given condition and return its index.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>arr: <code class="type">(<a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>.<T>|<a href="namespace_goog_array.html#goog.array.ArrayLike">goog.array.ArrayLike</a>)</code><dd>Array or array
|
|
like object over which to iterate.<dt>f: <code class="type">?function(this: S, T, <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>, ?): <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a></code><dd>The function to call
|
|
for every element. This function
|
|
takes 3 arguments (the element, the index and the array) and should
|
|
return a boolean.<dt>opt_obj: <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a>=</code><dd>An optional "this" context for the function.</dl><tr><th>Returns<tr><td><dl>The index of the last array element that passes the test,
|
|
or -1 if no element is found.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l565">code »</a><code class="type"><T, S></code> <span class="member"><a name="goog.array.findRight">goog.array.findRight</a> <span class="args">( arr, f, opt_obj )</span> ⇒ <code class="type">?T</code></span></div><p>Search an array (in reverse order) for the last element that satisfies a
|
|
given condition and return that element.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>arr: <code class="type">(<a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>.<T>|<a href="namespace_goog_array.html#goog.array.ArrayLike">goog.array.ArrayLike</a>)</code><dd>Array or array
|
|
like object over which to iterate.<dt>f: <code class="type">?function(this: S, T, <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>, ?): <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a></code><dd>The function to call
|
|
for every element. This function
|
|
takes 3 arguments (the element, the index and the array) and should
|
|
return a boolean.<dt>opt_obj: <code class="type">S=</code><dd>An optional "this" context for the function.</dl><tr><th>Returns<tr><td><dl>The last array element that passes the test, or null if no
|
|
element is found.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l1448">code »</a><span class="member"><a name="goog.array.flatten">goog.array.flatten</a> <span class="args">( var_args )</span> ⇒ <code class="type">!<a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a></code></span></div><p>Returns an array consisting of every argument with all arrays
|
|
expanded in-place recursively.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>var_args: <code class="type">...*</code><dd>The values to flatten.</dl><tr><th>Returns<tr><td><dl>An array containing the flattened values.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l196">code »</a><code class="type"><T, S></code> <span class="member"><a name="goog.array.forEach">goog.array.forEach</a> <span class="args">( arr, f, opt_obj )</span></span></div><p>Calls a function for each element in an array. Skips holes in the array.
|
|
See <code class="type"><a class="unresolved-link">http://tinyurl.com/developer-mozilla-org-array-foreach</a></code></summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>arr: <code class="type">(<a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>.<T>|<a href="namespace_goog_array.html#goog.array.ArrayLike">goog.array.ArrayLike</a>)</code><dd>Array or array like object over
|
|
which to iterate.<dt>f: <code class="type">?function(this: S, T, <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>, ?): ?</code><dd>The function to call for every
|
|
element. This function takes 3 arguments (the element, the index and the
|
|
array). The return value is ignored.<dt>opt_obj: <code class="type">S=</code><dd>The object to be used as the value of 'this' within f.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l229">code »</a><code class="type"><T, S></code> <span class="member"><a name="goog.array.forEachRight">goog.array.forEachRight</a> <span class="args">( arr, f, opt_obj )</span></span></div><p>Calls a function for each element in an array, starting from the last
|
|
element rather than the first.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>arr: <code class="type">(<a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>.<T>|<a href="namespace_goog_array.html#goog.array.ArrayLike">goog.array.ArrayLike</a>)</code><dd>Array or array
|
|
like object over which to iterate.<dt>f: <code class="type">?function(this: S, T, <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>, ?): ?</code><dd>The function to call for every
|
|
element. This function
|
|
takes 3 arguments (the element, the index and the array). The return
|
|
value is ignored.<dt>opt_obj: <code class="type">S=</code><dd>The object to be used as the value of 'this'
|
|
within f.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l108">code »</a><code class="type"><T></code> <span class="member"><a name="goog.array.indexOf">goog.array.indexOf</a> <span class="args">( arr, obj, opt_fromIndex )</span> ⇒ <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></code></span></div><p>Returns the index of the first element of an array with a specified value, or
|
|
-1 if the element is not present in the array.
|
|
|
|
See <code class="type"><a class="unresolved-link">http://tinyurl.com/developer-mozilla-org-array-indexof</a></code></summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>arr: <code class="type">(<a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>.<T>|<a href="namespace_goog_array.html#goog.array.ArrayLike">goog.array.ArrayLike</a>)</code><dd>The array to be searched.<dt>obj: <code class="type">T</code><dd>The object for which we are searching.<dt>opt_fromIndex: <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>=</code><dd>The index at which to start the search. If
|
|
omitted the search starts at index 0.</dl><tr><th>Returns<tr><td><dl>The index of the first matching array element.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l641">code »</a><code class="type"><T></code> <span class="member"><a name="goog.array.insert">goog.array.insert</a> <span class="args">( arr, obj )</span></span></div><p>Pushes an item into an array, if it's not already in the array.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>arr: <code class="type"><a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>.<T></code><dd>Array into which to insert the item.<dt>obj: <code class="type">T</code><dd>Value to add.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l667">code »</a><span class="member"><a name="goog.array.insertArrayAt">goog.array.insertArrayAt</a> <span class="args">( arr, elementsToAdd, opt_i )</span></span></div><p>Inserts at the given index of the array, all elements of another array.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>arr: <code class="type"><a href="namespace_goog_array.html#goog.array.ArrayLike">goog.array.ArrayLike</a></code><dd>The array to modify.<dt>elementsToAdd: <code class="type"><a href="namespace_goog_array.html#goog.array.ArrayLike">goog.array.ArrayLike</a></code><dd>The array of elements to add.<dt>opt_i: <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>=</code><dd>The index at which to insert the object. If omitted,
|
|
treated as 0. A negative index is counted from the end of the array.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l655">code »</a><span class="member"><a name="goog.array.insertAt">goog.array.insertAt</a> <span class="args">( arr, obj, opt_i )</span></span></div><p>Inserts an object at the given index of the array.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>arr: <code class="type"><a href="namespace_goog_array.html#goog.array.ArrayLike">goog.array.ArrayLike</a></code><dd>The array to modify.<dt>obj: <code class="type">*</code><dd>The object to insert.<dt>opt_i: <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>=</code><dd>The index at which to insert the object. If omitted,
|
|
treated as 0. A negative index is counted from the end of the array.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l680">code »</a><code class="type"><T></code> <span class="member"><a name="goog.array.insertBefore">goog.array.insertBefore</a> <span class="args">( arr, obj, opt_obj2 )</span></span></div><p>Inserts an object into an array before a specified object.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>arr: <code class="type"><a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>.<T></code><dd>The array to modify.<dt>obj: <code class="type">T</code><dd>The object to insert.<dt>opt_obj2: <code class="type">T=</code><dd>The object before which obj should be inserted. If obj2
|
|
is omitted or not found, obj is inserted at the end of the array.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l614">code »</a><span class="member"><a name="goog.array.isEmpty">goog.array.isEmpty</a> <span class="args">( arr )</span> ⇒ <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a></code></span></div><p>Whether the array is empty.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>arr: <code class="type"><a href="namespace_goog_array.html#goog.array.ArrayLike">goog.array.ArrayLike</a></code><dd>The array to test.</dl><tr><th>Returns<tr><td><dl>true if empty.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l1184">code »</a><code class="type"><T></code> <span class="member"><a name="goog.array.isSorted">goog.array.isSorted</a> <span class="args">( arr, opt_compareFn, opt_strict )</span> ⇒ <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a></code></span></div><p>Tells if the array is sorted.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>arr: <code class="type">!<a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>.<T></code><dd>The array.<dt>opt_compareFn: <code class="type">?function(T, T): <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>=</code><dd>Function to compare the
|
|
array elements.
|
|
Should take 2 arguments to compare, and return a negative number, zero,
|
|
or a positive number depending on whether the first argument is less
|
|
than, equal to, or greater than the second.<dt>opt_strict: <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a>=</code><dd>If true no equal elements are allowed.</dl><tr><th>Returns<tr><td><dl>Whether the array is sorted.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l786">code »</a><code class="type"><T></code> <span class="member"><a name="goog.array.join">goog.array.join</a> <span class="args">( var_args )</span> ⇒ <code class="type">!<a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>.<T></code></span></div><p>Returns a new array that contains the contents of all the arrays passed.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>var_args</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l78">code »</a><code class="type"><T></code> <span class="member"><a name="goog.array.last">goog.array.last</a> <span class="args">( array )</span> ⇒ <code class="type">T</code></span></div><p>Returns the last element in an array without removing it.
|
|
Same as goog.array.peek.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>array: <code class="type">(<a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>.<T>|<a href="namespace_goog_array.html#goog.array.ArrayLike">goog.array.ArrayLike</a>)</code><dd>The array.</dl><tr><th>Returns<tr><td><dl>Last item in array.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l150">code »</a><code class="type"><T></code> <span class="member"><a name="goog.array.lastIndexOf">goog.array.lastIndexOf</a> <span class="args">( arr, obj, opt_fromIndex )</span> ⇒ <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></code></span></div><p>Returns the index of the last element of an array with a specified value, or
|
|
-1 if the element is not present in the array.
|
|
|
|
See <code class="type"><a class="unresolved-link">http://tinyurl.com/developer-mozilla-org-array-lastindexof</a></code></summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>arr: <code class="type">(!<a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>.<T>|!<a href="namespace_goog_array.html#goog.array.ArrayLike">goog.array.ArrayLike</a>)</code><dd>The array to be searched.<dt>obj: <code class="type">T</code><dd>The object for which we are searching.<dt>opt_fromIndex: <code class="type">?<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>=</code><dd>The index at which to start the search. If
|
|
omitted the search starts at the end of the array.</dl><tr><th>Returns<tr><td><dl>The index of the last matching array element.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l300">code »</a><code class="type"><THIS, VALUE, RESULT></code> <span class="member"><a name="goog.array.map">goog.array.map</a> <span class="args">( arr, f, opt_obj )</span> ⇒ <code class="type">!<a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>.<RESULT></code></span></div><p>Calls a function for each element in an array and inserts the result into a
|
|
new array.
|
|
|
|
See <code class="type"><a class="unresolved-link">http://tinyurl.com/developer-mozilla-org-array-map</a></code></summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>arr: <code class="type">(<a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>.<VALUE>|<a href="namespace_goog_array.html#goog.array.ArrayLike">goog.array.ArrayLike</a>)</code><dd>Array or array like object
|
|
over which to iterate.<dt>f: <code class="type">function(this: THIS, VALUE, <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>, ?): RESULT</code><dd>The function to call
|
|
for every element. This function takes 3 arguments (the element,
|
|
the index and the array) and should return something. The result will be
|
|
inserted into a new array.<dt>opt_obj: <code class="type">THIS=</code><dd>The object to be used as the value of 'this' within f.</dl><tr><th>Returns<tr><td><dl>a new array with the results from f.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l1501">code »</a><span class="member"><a name="goog.array.moveItem">goog.array.moveItem</a> <span class="args">( arr, fromIndex, toIndex )</span></span></div><p>Moves one item of an array to a new position keeping the order of the rest
|
|
of the items. Example use case: keeping a list of JavaScript objects
|
|
synchronized with the corresponding list of DOM elements after one of the
|
|
elements has been dragged to a new position.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>arr: <code class="type">!(<a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>|<a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Functions_and_function_scope/arguments">Arguments</a>|{length: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>})</code><dd>The array to modify.<dt>fromIndex: <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></code><dd>Index of the item to move between 0 and
|
|
<code >arr.length - 1</code>.<dt>toIndex: <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></code><dd>Target index between 0 and <code >arr.length - 1</code>.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l66">code »</a><code class="type"><T></code> <span class="member"><a name="goog.array.peek">goog.array.peek</a> <span class="args">( array )</span> ⇒ <code class="type">T</code></span></div><p>Returns the last element in an array without removing it.
|
|
Same as goog.array.last.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>array: <code class="type">(<a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>.<T>|<a href="namespace_goog_array.html#goog.array.ArrayLike">goog.array.ArrayLike</a>)</code><dd>The array.</dl><tr><th>Returns<tr><td><dl>Last item in array.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l1396">code »</a><span class="member"><a name="goog.array.range">goog.array.range</a> <span class="args">( startOrEnd, opt_end, opt_step )</span> ⇒ <code class="type">!<a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>.<<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>></code></span></div><p>Creates a range of numbers in an arithmetic progression.
|
|
|
|
Range takes 1, 2, or 3 arguments:
|
|
<pre>
|
|
range(5) is the same as range(0, 5, 1) and produces [0, 1, 2, 3, 4]
|
|
range(2, 5) is the same as range(2, 5, 1) and produces [2, 3, 4]
|
|
range(-2, -5, -1) produces [-2, -3, -4]
|
|
range(-2, -5, 1) produces [], since stepping by 1 wouldn't ever reach -5.
|
|
</pre></summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>startOrEnd: <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></code><dd>The starting value of the range if an end argument
|
|
is provided. Otherwise, the start value is 0, and this is the end value.<dt>opt_end: <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>=</code><dd>The optional end value of the range.<dt>opt_step: <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>=</code><dd>The step size between range values. Defaults to 1
|
|
if opt_step is undefined or 0.</dl><tr><th>Returns<tr><td><dl>An array of numbers for the requested range. May be
|
|
an empty array if adding the step would not converge toward the end
|
|
value.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l345">code »</a><code class="type"><T, S, R></code> <span class="member"><a name="goog.array.reduce">goog.array.reduce</a> <span class="args">( arr, f, val, opt_obj )</span> ⇒ <code class="type">R</code></span></div><p>Passes every element of an array into a function and accumulates the result.
|
|
|
|
See <code class="type"><a class="unresolved-link">http://tinyurl.com/developer-mozilla-org-array-reduce</a></code>
|
|
|
|
For example:
|
|
var a = [1, 2, 3, 4];
|
|
goog.array.reduce(a, function(r, v, i, arr) {return r + v;}, 0);
|
|
returns 10</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>arr: <code class="type">(<a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>.<T>|<a href="namespace_goog_array.html#goog.array.ArrayLike">goog.array.ArrayLike</a>)</code><dd>Array or array
|
|
like object over which to iterate.<dt>f: <code class="type">?function(this: S, R, T, <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>, ?): R</code><dd>The function to call for
|
|
every element. This function
|
|
takes 4 arguments (the function's previous result or the initial value,
|
|
the value of the current array element, the current array index, and the
|
|
array itself)
|
|
function(previousValue, currentValue, index, array).<dt>val: <code class="type">?</code><dd>The initial value to pass into the function on the first call.<dt>opt_obj: <code class="type">S=</code><dd>The object to be used as the value of 'this'
|
|
within f.</dl><tr><th>Returns<tr><td><dl>Result of evaluating f repeatedly across the values of the array.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l390">code »</a><code class="type"><T, S, R></code> <span class="member"><a name="goog.array.reduceRight">goog.array.reduceRight</a> <span class="args">( arr, f, val, opt_obj )</span> ⇒ <code class="type">R</code></span></div><p>Passes every element of an array into a function and accumulates the result,
|
|
starting from the last element and working towards the first.
|
|
|
|
See <code class="type"><a class="unresolved-link">http://tinyurl.com/developer-mozilla-org-array-reduceright</a></code>
|
|
|
|
For example:
|
|
var a = ['a', 'b', 'c'];
|
|
goog.array.reduceRight(a, function(r, v, i, arr) {return r + v;}, '');
|
|
returns 'cba'</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>arr: <code class="type">(<a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>.<T>|<a href="namespace_goog_array.html#goog.array.ArrayLike">goog.array.ArrayLike</a>)</code><dd>Array or array
|
|
like object over which to iterate.<dt>f: <code class="type">?function(this: S, R, T, <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>, ?): R</code><dd>The function to call for
|
|
every element. This function
|
|
takes 4 arguments (the function's previous result or the initial value,
|
|
the value of the current array element, the current array index, and the
|
|
array itself)
|
|
function(previousValue, currentValue, index, array).<dt>val: <code class="type">?</code><dd>The initial value to pass into the function on the first call.<dt>opt_obj: <code class="type">S=</code><dd>The object to be used as the value of 'this'
|
|
within f.</dl><tr><th>Returns<tr><td><dl>Object returned as a result of evaluating f repeatedly across the
|
|
values of the array.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l698">code »</a><code class="type"><T></code> <span class="member"><a name="goog.array.remove">goog.array.remove</a> <span class="args">( arr, obj )</span> ⇒ <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a></code></span></div><p>Removes the first occurrence of a particular value from an array.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>arr: <code class="type">(<a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>.<T>|<a href="namespace_goog_array.html#goog.array.ArrayLike">goog.array.ArrayLike</a>)</code><dd>Array from which to remove
|
|
value.<dt>obj: <code class="type">T</code><dd>Object to remove.</dl><tr><th>Returns<tr><td><dl>True if an element was removed.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l715">code »</a><span class="member"><a name="goog.array.removeAt">goog.array.removeAt</a> <span class="args">( arr, i )</span> ⇒ <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a></code></span></div><p>Removes from an array the element at index i</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>arr: <code class="type"><a href="namespace_goog_array.html#goog.array.ArrayLike">goog.array.ArrayLike</a></code><dd>Array or array like object from which to
|
|
remove value.<dt>i: <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></code><dd>The index to remove.</dl><tr><th>Returns<tr><td><dl>True if an element was removed.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l950">code »</a><code class="type"><T></code> <span class="member"><a name="goog.array.removeDuplicates">goog.array.removeDuplicates</a> <span class="args">( arr, opt_rv, opt_hashFn )</span></span></div><p>Removes all duplicates from an array (retaining only the first
|
|
occurrence of each array element). This function modifies the
|
|
array in place and doesn't change the order of the non-duplicate items.
|
|
|
|
For objects, duplicates are identified as having the same unique ID as
|
|
defined by <code class="type"><a href="namespace_goog.html#goog.getUid">goog.getUid</a></code>.
|
|
|
|
Alternatively you can specify a custom hash function that returns a unique
|
|
value for each item in the array it should consider unique.
|
|
|
|
Runtime: N,
|
|
Worstcase space: 2N (no dupes)</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>arr: <code class="type">(<a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>.<T>|<a href="namespace_goog_array.html#goog.array.ArrayLike">goog.array.ArrayLike</a>)</code><dd>The array from which to remove
|
|
duplicates.<dt>opt_rv: <code class="type"><a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>=</code><dd>An optional array in which to return the results,
|
|
instead of performing the removal inplace. If specified, the original
|
|
array will remain unchanged.<dt>opt_hashFn: <code class="type">function(T): <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>=</code><dd>An optional function to use to
|
|
apply to every item in the array. This function should return a unique
|
|
value for each item in the array it should consider unique.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l737">code »</a><code class="type"><T, S></code> <span class="member"><a name="goog.array.removeIf">goog.array.removeIf</a> <span class="args">( arr, f, opt_obj )</span> ⇒ <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a></code></span></div><p>Removes the first value that satisfies the given condition.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>arr: <code class="type">(<a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>.<T>|<a href="namespace_goog_array.html#goog.array.ArrayLike">goog.array.ArrayLike</a>)</code><dd>Array or array
|
|
like object over which to iterate.<dt>f: <code class="type">?function(this: S, T, <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>, ?): <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a></code><dd>The function to call
|
|
for every element. This function
|
|
takes 3 arguments (the element, the index and the array) and should
|
|
return a boolean.<dt>opt_obj: <code class="type">S=</code><dd>An optional "this" context for the function.</dl><tr><th>Returns<tr><td><dl>True if an element was removed.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l1432">code »</a><code class="type"><VALUE></code> <span class="member"><a name="goog.array.repeat">goog.array.repeat</a> <span class="args">( value, n )</span> ⇒ <code class="type">!<a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>.<VALUE></code></span></div><p>Returns an array consisting of the given value repeated N times.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>value: <code class="type">VALUE</code><dd>The value to repeat.<dt>n: <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></code><dd>The repeat count.</dl><tr><th>Returns<tr><td><dl>An array with the repeated value.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l1476">code »</a><code class="type"><T></code> <span class="member"><a name="goog.array.rotate">goog.array.rotate</a> <span class="args">( array, n )</span> ⇒ <code class="type">!<a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>.<T></code></span></div><p>Rotates an array in-place. After calling this method, the element at
|
|
index i will be the element previously at index (i - n) %
|
|
array.length, for all values of i between 0 and array.length - 1,
|
|
inclusive.
|
|
|
|
For example, suppose list comprises [t, a, n, k, s]. After invoking
|
|
rotate(array, 1) (or rotate(array, -4)), array will comprise [s, t, a, n, k].</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>array: <code class="type">!<a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>.<T></code><dd>The array to rotate.<dt>n: <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></code><dd>The amount to rotate.</dl><tr><th>Returns<tr><td><dl>The array.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l1559">code »</a><span class="member"><a name="goog.array.shuffle">goog.array.shuffle</a> <span class="args">( arr, opt_randFn )</span></span></div><p>Shuffles the values in the specified array using the Fisher-Yates in-place
|
|
shuffle (also known as the Knuth Shuffle). By default, calls Math.random()
|
|
and so resets the state of that random number generator. Similarly, may reset
|
|
the state of the any other specified random number generator.
|
|
|
|
Runtime: O(n)</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>arr: <code class="type">!<a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a></code><dd>The array to be shuffled.<dt>opt_randFn: <code class="type">function(): <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>=</code><dd>Optional random function to use for
|
|
shuffling.
|
|
Takes no arguments, and returns a random number on the interval [0, 1).
|
|
Defaults to Math.random() using JavaScript's built-in Math library.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l911">code »</a><code class="type"><T></code> <span class="member"><a name="goog.array.slice">goog.array.slice</a> <span class="args">( arr, start, opt_end )</span> ⇒ <code class="type">!<a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>.<T></code></span></div><p>Returns a new array from a segment of an array. This is a generic version of
|
|
Array slice. This means that it might work on other objects similar to
|
|
arrays, such as the arguments object.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>arr: <code class="type">(<a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>.<T>|<a href="namespace_goog_array.html#goog.array.ArrayLike">goog.array.ArrayLike</a>)</code><dd>The array from
|
|
which to copy a segment.<dt>start: <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></code><dd>The index of the first element to copy.<dt>opt_end: <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>=</code><dd>The index after the last element to copy.</dl><tr><th>Returns<tr><td><dl>A new array containing the specified segment of the
|
|
original array.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l426">code »</a><code class="type"><T, S></code> <span class="member"><a name="goog.array.some">goog.array.some</a> <span class="args">( arr, f, opt_obj )</span> ⇒ <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a></code></span></div><p>Calls f for each element of an array. If any call returns true, some()
|
|
returns true (without checking the remaining elements). If all calls
|
|
return false, some() returns false.
|
|
|
|
See <code class="type"><a class="unresolved-link">http://tinyurl.com/developer-mozilla-org-array-some</a></code></summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>arr: <code class="type">(<a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>.<T>|<a href="namespace_goog_array.html#goog.array.ArrayLike">goog.array.ArrayLike</a>)</code><dd>Array or array
|
|
like object over which to iterate.<dt>f: <code class="type">?function(this: S, T, <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>, ?): <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a></code><dd>The function to call for
|
|
for every element. This function takes 3 arguments (the element, the
|
|
index and the array) and should return a boolean.<dt>opt_obj: <code class="type">S=</code><dd>The object to be used as the value of 'this'
|
|
within f.</dl><tr><th>Returns<tr><td><dl>true if any element passes the test.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l1114">code »</a><code class="type"><T></code> <span class="member"><a name="goog.array.sort">goog.array.sort</a> <span class="args">( arr, opt_compareFn )</span></span></div><p>Sorts the specified array into ascending order. If no opt_compareFn is
|
|
specified, elements are compared using
|
|
<code>goog.array.defaultCompare</code>, which compares the elements using
|
|
the built in < and > operators. This will produce the expected behavior
|
|
for homogeneous arrays of String(s) and Number(s), unlike the native sort,
|
|
but will give unpredictable results for heterogenous lists of strings and
|
|
numbers with different numbers of digits.
|
|
|
|
This sort is not guaranteed to be stable.
|
|
|
|
Runtime: Same as <code>Array.prototype.sort</code></summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>arr: <code class="type"><a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>.<T></code><dd>The array to be sorted.<dt>opt_compareFn: <code class="type">?function(T, T): <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>=</code><dd>Optional comparison
|
|
function by which the
|
|
array is to be ordered. Should take 2 arguments to compare, and return a
|
|
negative number, zero, or a positive number depending on whether the
|
|
first argument is less than, equal to, or greater than the second.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l1164">code »</a><span class="member"><a name="goog.array.sortObjectsByKey">goog.array.sortObjectsByKey</a> <span class="args">( arr, key, opt_compareFn )</span></span></div><p>Sorts an array of objects by the specified object key and compare
|
|
function. If no compare function is provided, the key values are
|
|
compared in ascending order using <code>goog.array.defaultCompare</code>.
|
|
This won't work for keys that get renamed by the compiler. So use
|
|
{'foo': 1, 'bar': 2} rather than {foo: 1, bar: 2}.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>arr: <code class="type"><a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>.<<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a>></code><dd>An array of objects to sort.<dt>key: <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a></code><dd>The object key to sort by.<dt>opt_compareFn: <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function">Function</a>=</code><dd>The function to use to compare key
|
|
values.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l890">code »</a><code class="type"><T></code> <span class="member"><a name="goog.array.splice">goog.array.splice</a> <span class="args">( arr, index, howMany, var_args )</span> ⇒ <code class="type">!<a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>.<T></code></span></div><p>Adds or removes elements from an array. This is a generic version of Array
|
|
splice. This means that it might work on other objects similar to arrays,
|
|
such as the arguments object.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>arr: <code class="type">(<a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>.<T>|<a href="namespace_goog_array.html#goog.array.ArrayLike">goog.array.ArrayLike</a>)</code><dd>The array to modify.<dt>index: <code class="type">(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>|<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Undefined">undefined</a>)</code><dd>The index at which to start changing the
|
|
array. If not defined, treated as 0.<dt>howMany: <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></code><dd>How many elements to remove (0 means no removal. A
|
|
value below 0 is treated as zero and so is any other non number. Numbers
|
|
are floored).<dt>var_args: <code class="type">...T</code><dd>Optional, additional elements to insert into the
|
|
array.</dl><tr><th>Returns<tr><td><dl>the removed elements.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l1138">code »</a><code class="type"><T></code> <span class="member"><a name="goog.array.stableSort">goog.array.stableSort</a> <span class="args">( arr, opt_compareFn )</span></span></div><p>Sorts the specified array into ascending order in a stable way. If no
|
|
opt_compareFn is specified, elements are compared using
|
|
<code>goog.array.defaultCompare</code>, which compares the elements using
|
|
the built in < and > operators. This will produce the expected behavior
|
|
for homogeneous arrays of String(s) and Number(s).
|
|
|
|
Runtime: Same as <code>Array.prototype.sort</code>, plus an additional
|
|
O(n) overhead of copying the array twice.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>arr: <code class="type"><a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>.<T></code><dd>The array to be sorted.<dt>opt_compareFn: <code class="type">?function(T, T): <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>=</code><dd>Optional comparison function
|
|
by which the array is to be ordered. Should take 2 arguments to compare,
|
|
and return a negative number, zero, or a positive number depending on
|
|
whether the first argument is less than, equal to, or greater than the
|
|
second.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l802">code »</a><code class="type"><T></code> <span class="member"><a name="goog.array.toArray">goog.array.toArray</a> <span class="args">( object )</span> ⇒ <code class="type">!<a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>.<T></code></span></div><p>Converts an object to an array.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>object: <code class="type">(<a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>.<T>|<a href="namespace_goog_array.html#goog.array.ArrayLike">goog.array.ArrayLike</a>)</code><dd>The object to convert to an
|
|
array.</dl><tr><th>Returns<tr><td><dl>The object converted into an array. If object has a
|
|
length property, every property indexed with a non-negative number
|
|
less than length will be included in the result. If object does not
|
|
have a length property, an empty array will be returned.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l1367">code »</a><code class="type"><T, S></code> <span class="member"><a name="goog.array.toObject">goog.array.toObject</a> <span class="args">( arr, keyFunc, opt_obj )</span> ⇒ <code class="type">!<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a>.<T></code></span></div><p>Creates a new object built from the provided array and the key-generation
|
|
function.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>arr: <code class="type">(<a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>.<T>|<a href="namespace_goog_array.html#goog.array.ArrayLike">goog.array.ArrayLike</a>)</code><dd>Array or array like object over
|
|
which to iterate whose elements will be the values in the new object.<dt>keyFunc: <code class="type">?function(this: S, T, <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>, ?): <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a></code><dd>The function to
|
|
call for every element. This function takes 3 arguments (the element, the
|
|
index and the array) and should return a string that will be used as the
|
|
key for the element in the new object. If the function returns the same
|
|
key for more than one element, the value for that key is
|
|
implementation-defined.<dt>opt_obj: <code class="type">S=</code><dd>The object to be used as the value of 'this'
|
|
within keyFunc.</dl><tr><th>Returns<tr><td><dl>The new object.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l1525">code »</a><span class="member"><a name="goog.array.zip">goog.array.zip</a> <span class="args">( var_args )</span> ⇒ <code class="type">!<a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a></code></span></div><p>Creates a new array for which the element at position i is an array of the
|
|
ith element of the provided arrays. The returned array will only be as long
|
|
as the shortest array provided; additional values are ignored. For example,
|
|
the result of zipping [1, 2] and [3, 4, 5] is [[1,3], [2, 4]].
|
|
|
|
This is similar to the zip() function in Python. See <code class="type"><a class="unresolved-link">http://docs.python.org/library/functions.html#zip</a></code></summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>var_args: <code class="type">...!<a href="namespace_goog_array.html#goog.array.ArrayLike">goog.array.ArrayLike</a></code><dd>Arrays to be combined.</dl><tr><th>Returns<tr><td><dl>A new array of arrays created from provided arrays.</dl></table></div></details></div></div></section><section id="static-properties"><h2>Global Properties</h2><div class="wrap-details private"><div><details><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l85">code »</a><span class="member"><a name="goog.array.ARRAY_PROTOTYPE_">goog.array.ARRAY_PROTOTYPE_</a> : <code class="type"><a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array.prototype</a></code></span></div><p>Reference to the original <code >Array.prototype</code>.</summary></details></div></div></section><section id="compiler-constants"><h2>Compiler Constants</h2><div class="wrap-details public"><div><details><summary><div><a class="source" href="source/lib/goog/array/array.js.src.html#l50">code »</a><span class="member"><a name="goog.array.ASSUME_NATIVE_FUNCTIONS">goog.array.ASSUME_NATIVE_FUNCTIONS</a> : <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a></code></span></div></summary></details></div></div></section></main><nav id="topnav"><div><div id="menubutton"><label for="sidenav-toggle">Menu</label></div><form id="searchbox"><div><input type="search" placeholder="Search" tabindex="1"></div></form></div></nav><nav id="sidenav"><input type="checkbox" id="sidenav-types-ctrl" /><input type="checkbox" id="sidenav-files-ctrl" /><input type="checkbox" id="sidenav-modules-ctrl" /><a id="sidenav-overview"><div><h4>Overview</h4></div></a><div id="sidenav-types"><label for="sidenav-types-ctrl"><h4>Types</h4></label><i>No data</i></div><div id="sidenav-modules"><label for="sidenav-modules-ctrl"><h4>Modules</h4></label><i>No data</i></div><div id="sidenav-files"><label for="sidenav-files-ctrl"><h4>Files</h4></label><i>No data</i></div><a href="license.html"><div><h4>License</h4></div></a></nav><div id="push-footer"></div></div><footer><a href="https://github.com/jleyba/js-dossier">Generated by dossier</a></footer><script src="types.js"></script><script src="dossier.js"></script> |