CS2613/labs/L10/arrays.js
2022-10-17 10:24:22 -03:00

18 lines
305 B
JavaScript

function range(start, end, step=1) {
let result = [];
for (let i = start; i <= end; i += step) {
result.push(i);
}
return result;
}
function sum(array) {
let result = 0;
for (let i = 0; i < array.length; i++) {
result += array[i];
}
return result;
}
exports.range = range;
exports.sum = sum;