📜  range(min,max) js - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:24.503000             🧑  作者: Mango

代码示例1
function range(min, max) {
    if (max === undefined && min !== undefined) {
          return [...Array(min+1).keys()];
    } else if (min !== undefined) {
        return [...Array(max-min+1).keys()].map(elm => elm+min);
    } else {
        return;
    }
}

range(5);// => [ 0, 1, 2, 3, 4, 5 ]
range(5,10);// => [ 5, 6, 7, 8, 9, 10 ]