Javascript 自制range函数实现

function range(start, stop, step)
{
    if (typeof(stop) == 'undefined')
    {
        // one param defined
        stop = start;
        start = 0;
    }
    if (typeof(step) == 'undefined')
    {
        step = 1;
    }
    if ((step > 0 && start >= stop) || (step < 0 && start <= stop))
    {
        return [];
    }
    var result = [];
    for (var i = start; step > 0 ? i < stop : i > stop; i += step)
    {
        result.push(i);
    }
    return result;
}
阅读更多
换一批

没有更多推荐了,返回首页