yui-array.js revision eb86457f85638a9eb7c4d5f84eb367d24061abfb
919N/A * Adds the following array utilities to the YUI instance 919N/A * Y.Array(o) returns an array: 919N/A * - Arrays are return unmodified unless the start position is specified. 919N/A * - "Array-like" collections (@see Array.test) are converted to arrays 919N/A * - For everything else, a new array is created with the input as the sole item 919N/A * - The start position is used if the input is or is like an array to return 919N/A * a subset of the collection. 550N/A * @TODO this will not automatically convert elements that are also collections 550N/A * such as forms and selects. Passing true as the third param will 550N/A * @param o the item to arrayify 550N/A * @param i {int} if an array or array-like, this is the start index 550N/A * @param al {boolean} if true, it forces the array-like fork. This 550N/A * can be used to avoid multiple array.test calls. 550N/A * @return {Array} the resulting array 550N/A // // return (i) ? o.slice(i) : o; 550N/A // return Native.slice.call(o, i || 0); * Evaluates the input to determine if it is an array, array-like, or * something else. This is used to handle the arguments collection * available within functions, and HTMLElement collections * @todo current implementation (intenionally) will not implicitly * handle html elements that are array-like (forms, selects, etc). * @return {int} a number indicating the results: * 0: Not an array or an array-like collection * 2: array-like collection. // indexed, but no tagName (element) or alert (window) * 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 {YUI} the YUI instance for (i =
0; i < l; i=i+
1) {
f.
call(o || Y, a[i], i, a);
* Returns an object using the first array as keys, and * the second as values. If the second array is not * provided the value is set to true for each. * @param k {Array} keyset * @param v {Array} optional valueset * @return {object} the hash A.
hash =
function(k, v) {
o[k[i]] = (
vl &&
vl > i) ? v[i] :
true;
* Returns the index of the first item in the array * that contains the specified value, -1 if the * @param a {Array} the array to search * @param val the value to search for * @return {int} the index of the item that contains the value or -1 for (
var i=
0; i<a.
length; i=i+
1) {
* Numeric sort convenience function. * Y.ArrayAssert.itemsAreEqual([1, 2, 3], [3, 1, 2].sort(Y.Array.numericSort));