T.array.containsは、配列に所定の要素が含まれているかどうかを判断します.

8795 ワード

// Copyright (c) 2009, Baidu Inc. All rights reserved.

// 

// Licensed under the BSD License

// you may not use this file except in compliance with the License.

// You may obtain a copy of the License at

// 

//      http:// tangram.baidu.com/license.html

// 

// Unless required by applicable law or agreed to in writing, software

// distributed under the License is distributed on an "AS-IS" BASIS,

// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

// See the License for the specific language governing permissions and

// limitations under the License.

 /**

 * @namespace T Tangram   

 * @name T

 * @version 1.3.9

*/



/**

 *   baidu 

 * @author: allstar, erik, meizz, berg

 */

var T,

    baidu = T = baidu || {version: "1.3.9"}; 



//  guid,       Tangram   

//         window[undefined]

baidu.guid = "$BAIDU$";



//Tangram        

//           ,     window[baidu.guid] 

window[baidu.guid] = window[baidu.guid] || {};





/**

 * @namespace baidu.array        。

 */



baidu.array = baidu.array || {};



/**

 *               

 * @name baidu.array.indexOf

 * @function

 * @grammar baidu.array.indexOf(source, match[, fromIndex])

 * @param {Array} source        

 * @param {Any} match   IC    

 * @param {number} [fromIndex]           ,     ,  source.length+fromIndex      

 * @see baidu.array.find,baidu.array.lastIndexOf

 *             

 * @returns {number}          ,       -1

 */

baidu.array.indexOf = function (source, match, fromIndex) {

    var len = source.length,

        iterator = match;

        

    fromIndex = fromIndex | 0;

    if(fromIndex < 0){//  0

        fromIndex = Math.max(0, len + fromIndex)

    }

    for ( ; fromIndex < len; fromIndex++) {

        if(fromIndex in source && source[fromIndex] === match) {

            return fromIndex;

        }

    }

    

    return -1;

};





/**

 *   IC                

 * @name baidu.array.contains

 * @function

 * @grammar baidu.array.contains(source, obj)

 * @param {Array} source        .

 * @param {Any} obj       .

 * @return {boolean}     .

 * @author berg

 */

baidu.array.contains = function(source, obj) {

    return (baidu.array.indexOf(source, obj) >= 0);

};