Skip to main content

Ivan Teoh

Something personal yet public

167-exercise411.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;
}
function sum(numbers) {
    result = 0;
    for (var i = 0; i < numbers.length; i++) {
        result += numbers[i];
    }
    return result;
}
document.write(sum(range(1, 10))); // 55