Skip to main content

Ivan Teoh

Something personal yet public

167-exercise410.js

(Source)

function range(num, start) {
    var list = [];
    if (arguments.length < 2) {
        for (var i = 0; i <= num; i++) {
            list[i] = i;
        }
    } else {
        for (var x = 0, y = num; y <= start; x++, y++) {
            list[x] = y;
        }
    }
    return list;
}
document.write(range(5)); // 0, 1, 2, 3, 4, 5
document.write(range(2, 5)); // 2, 3, 4, 5