]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - jssource/src_files/include/javascript/yui3/build/collection/arraylist-filter.js
Release 6.5.0
[Github/sugarcrm.git] / jssource / src_files / include / javascript / yui3 / build / collection / arraylist-filter.js
1 /*
2 Copyright (c) 2010, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.com/yui/license.html
5 version: 3.3.0
6 build: 3167
7 */
8 YUI.add('arraylist-filter', function(Y) {
9
10 /**
11  * Collection utilities beyond what is provided in the YUI core
12  * @module collection
13  * @submodule arraylist-filter
14  */
15
16 /**
17  * Adds filter method to ArrayList prototype
18  * @class ArrayList~filter
19  */
20 Y.mix(Y.ArrayList.prototype, {
21
22     /**
23      * <p>Create a new ArrayList (or augmenting class instance) from a subset
24      * of items as determined by the boolean function passed as the
25      * argument.  The original ArrayList is unchanged.</p>
26      *
27      * <p>The validator signature is <code>validator( item )</code>.</p>
28      *
29      * @method filter
30      * @param { Function } validator Boolean function to determine in or out.
31      * @return { ArrayList } New instance based on who passed the validator.
32      */
33     filter: function(validator) {
34         var items = [];
35
36         Y.Array.each(this._items, function(item, i) {
37             item = this.item(i);
38
39             if (validator(item)) {
40                 items.push(item);
41             }
42         }, this);
43
44         return new this.constructor(items);
45     }
46
47 });
48
49
50 }, '3.3.0' ,{requires:['arraylist']});