如何计算在起始值和结束值之间存在的元素?

时间:2013-12-20 17:10:53

标签: java javascript jquery

我需要你身边的一些逻辑。我想计算出现的元素数量 n-在起始值和结束值之间 像

Input :Starting point in 1
          end point is :10

Search :2

count :1(only 2)

Input :Starting point in 1
          end point is :20

Search :2

count :3(only 2, 12 ,20)
function(var start,var end,var searchItem){
for(var start;start<=end;start++)

}

1 个答案:

答案 0 :(得分:0)

尝试,

function search(start, end, searchItem) {

    var xCnt = 0;

    for (var start = 0; start <= end; start++) {

        if ((start + '').indexOf(searchItem + '') >= 0) {
            xCnt += 1;
        }

    }
    return xCnt;
}

DEMO