array-extras-debug.js revision 266bfbd67fc220029bdadabd3c49e733f9f39360
1549N/A * Collection utilities beyond what is provided in the YUI core 1549N/A * Adds the following array utilities to the YUI instance 1549N/A * (Y.Array). This is in addition to the methods provided 1549N/A * Returns the index of the last item in the array 1549N/A * that contains the specified value, -1 if the 1549N/A * @param a {Array} the array to search 1549N/A * @param val the value to search for 1549N/A * @return {int} the index of hte item that contains the value or -1 1549N/A * Returns a copy of the array with the duplicate entries removed 1549N/A * @param a {Array} the array to find the subset of uniques for 1549N/A * @param sort {bool} flag to denote if the array is sorted or not. Defaults to false, the more general operation 1549N/A * @return {Array} a copy of the array with duplicate entries removed 1549N/A // Note: the sort option doesn't really belong here... I think it was added 1549N/A // because there was a way to fast path the two operations together. That 1549N/A // implementation was not working, so I replaced it with the following. 1549N/A // Leaving it in so that the API doesn't get broken. * Executes the supplied function on each item in the array. * Returns a new array containing the items that the supplied * function returned true for. * @param a {Array} the array to iterate * @param f {Function} the function to execute on each item * @param o Optional context object * @return {Array} The items on which the supplied function * returned true. If no items matched an empty array is * The inverse of filter. Executes the supplied function on each item. * Returns a new array containing the items that the supplied * function returned *false* for. * @param a {Array} the array to iterate * @param f {Function} the function to execute on each item * @param o Optional context object * @return {Array} The items on which the supplied function A.
reject =
function(a, f, o) {
* Executes the supplied function on each item in the array. * @param a {Array} the array to iterate * @param f {Function} the function to execute on each item * @param o Optional context object * @return {boolean} true if every item in the array returns true * from the supplied function. for (
var i =
0, l = a.
length; i < l; i=i+
1) {
if (!f.
call(o, a[i], i, a)) {
* Executes the supplied function on each item in the array. * @param a {Array} the array to iterate * @param f {Function} the function to execute on each item * @param o Optional context object * @return {Array} A new array containing the return value * of the supplied function for each item in the original * Executes the supplied function on each item in the array. * Reduce "folds" the array into a single value. * @param a {Array} the array to iterate * @param init The initial value to start from * @param f {Function} the function to execute on each item. It * is responsible for returning the updated value of the * @param o Optional context object * @return A value that results from iteratively applying the * supplied function to each element in the array. function(a,
init, f, o) {
//Firefox's Array.reduce does not allow inclusion of a // thisObject, so we need to implement it manually function(a,
init, f, o) {
* Executes the supplied function on each item in the array, * searching for the first item that matches the supplied * @param a {Array} the array to search * @param f {Function} the function to execute on each item. * Iteration is stopped as soon as this function returns true * @param o Optional context object * @return {object} the first item that the supplied function * returns true for, or null if it never returns true A.
find =
function(a, f, o) {
for(
var i=
0, l = a.
length; i < l; i++) {
if (f.
call(o, a[i], i, a)) {
* Iterates over an array, returning a new array of all the elements * that match the supplied regular expression * @param a {Array} a collection to iterate over * @param pattern {RegExp} The regular expression to test against * @return {Array} All the items in the collection that * produce a match against the supplied regular expression. * If no items match, an empty array is returned. * Partitions an array into two new arrays, one with the items * that match the supplied function, and one with the items that * @method Array.partition * @param a {Array} a collection to iterate over * @paran f {Function} a function that will receive each item * in the collection and its index. * @param o Optional execution context of f. * @return An object with two members, 'matches' and 'rejects', * that are arrays containing the items that were selected or * rejected by the test function (or an empty array). * Creates an array of arrays by pairing the corresponding * elements of two arrays together into a new array. * @param a {Array} a collection to iterate over * @param a2 {Array} another collection whose members will be * paired with members of the first parameter * @return An array of arrays formed by pairing each element * of the first collection with an item in the second collection * having the corresponding index. A.
zip =
function (a,
a2) {