zoukankan      html  css  js  c++  java
  • 扩展Array方法

           Array.prototype.where = function (callback) {
                
    var array = []
                
    for (var i = 0; i < this.length; i++) {
                    
    if (callback.apply(this[i]) != false) {
                        array.push(
    this[i])
                    }
                }
                
    return array;
            }

            Array.prototype.each 
    = function (callback) {
                
    for (var i = 0; i < this.length; i++) {
                    
    if (callback.apply(this[i]) == false) {
                        
    break;
                    }
                }
            }

            
    var data = [];
            data.push({ min: 
    0, max: 100, value: 1 });
            data.push({ min: 
    51, max: 150, value: 2 });
            data.push({ min: 
    101, max: 200, value: 3 });
            data.push({ min: 
    151, max: 450, value: 4 });
            
    var N = 150;

            data.where(
    function () {
                
    return (this.min <= N && this.max >= N)
            }).each(
    function () {
                alert(
    this.value);
            });


  • 相关阅读:
    oracle常规操作
    shell 的算数运算
    sed 命令小结
    swing
    索引失效
    poj--1258--Agri-Net(最小生成树)
    CodeForces--626C--Block Towers (二分)
    Codeforces--629A--Far Relative’s Birthday Cake(暴力模拟)
    Codeforces--629B--Far Relative’s Problem(模拟)
    hdoj--5104--Primes Problem(素数打表)
  • 原文地址:https://www.cnblogs.com/goodspeed/p/1781451.html
Copyright © 2011-2022 走看看