zoukankan      html  css  js  c++  java
  • 【Array数组】every和some

    every和some 都是用来测试数组中的项是否满足某一条件。every只有当所有项全部满足时才返回true,some只有有一个满足就返回true。

    1、使用方法:  数组.every(测试函数,用作函数的this对象);

    当测试函数是封闭函数时,第二个参数必须为空。就是函数定义方式是 function myFun():void{}这种形式时,第二个参数必须为空。

    当测试函数定义方式为 myFunction:Function=function (obj:Object):void{}时,第二个参数代表用作函数的this对象。

    2、测试函数格式:function callback(item:*, index:int, array:Array):Boolean;

    item 代表数组中的某一项, index,代表数组的索引,array:代表数组本身。

    3、例子:

    var arr:Array = [15,7,12,15];
    var testEvery1:Boolean = arr.every(isNum);
    var testEvery2:Boolean = arr.every(isThanTen);
    trace(testEvery1);
    //true
    trace(testEvery2);
    //false
    var testSome1:Boolean = arr.some(isThanTen);
    trace(testSome1);
    //true
    
    //测试函数
    
    //是否是数字
    function isNum(item:*,index:int,arr:Array):Boolean
    {
        return item is Number;
    }
    
    
    //是否大于10
    function isThanTen(item:*,index:int,arr:Array):Boolean
    {
        return item>10;
    }
  • 相关阅读:
    模拟112 题解
    python 虚拟环境--virtualenv
    Flask基础
    通过yum安装mysql数据
    Python中function(函数)和methon(方法)的区别
    Django之路由分发系统
    OpenGL Shader in OpenCASCADE
    A Simple OpenGL Shader Example II
    Make Helix Curve in OpenCASCADE
    A Simple OpenGL Shader Example
  • 原文地址:https://www.cnblogs.com/ywl01/p/2582484.html
Copyright © 2011-2022 走看看