collection.js revision c7f25ad31c50e9c88e0c2712ee0c2f647e46f073
/**
* Collection utilities beyond what is provided in the YUI core
* @module yui
*/
/**
* Executes the supplied function on each item in the array.
* Returning true from the processing function will stop the
* processing of the remaining
* items.
* @method Array.some
* @param a {Array} the array to iterate
* @param f {Function} the function to execute on each item
* @param o Optional context object
* @static
* @return {boolean} true if the
*/
function (a, f, o) {
return Y;
} :
function (a, f, o) {
var l = a.length, i;
for (i=0; i<l; i=i+1) {
if (f.call(o, a[i], i, a)) {
return true;
}
}
return false;
};
/**
* Returns the index of the last item in the array
* that contains the specified value, -1 if the
* value isn't found.
* method Array.lastIndexOf
* @static
* @param a {Array} the array to search
* @param val the value to search for
* @return {int} the index of hte item that contains the value or -1
*/
function(a ,val) {
return a.lastIndexOf(val);
} :
function(a, val) {
if (a[i] === val) {
break;
}
}
return i;
};
/**
* Returns a copy of the array with the duplicate entries removed
* @method Array.unique
* @static
* @param a {Array} the array to find the subset of uniques for
* @param sort {bool} flag to denote if the array should be sorted or not. Defaults to true, this is a faster operation
* @return {Array} a copy of the array with duplicate entries removed
*/
if (s) {
b.sort();
while (i < b.length) {
if (b[i] === item) {
n = (n == -1 ? i : n);
i += 1;
} else if (s !== -1) {
b.splice(n, i-n);
i = n;
n = -1;
} else {
item = b[i];
i += 1;
}
}
return b;
} else {
while (i < b.length) {
item = b[i];
while ((n = b.lastIndexOf(item)) !== i) {
b.splice(n, 1);
}
i += 1;
}
return b;
}
};
}, '@VERSION@' );