diff --git a/chapter04.js b/chapter04.js index 12f6ef0..46094d9 100644 --- a/chapter04.js +++ b/chapter04.js @@ -9,42 +9,103 @@ // Problem 1: The sum of a range function range(start, end, step=1) { - // Your code here + var arr = []; + if(step < 0){ + for(i=start;i>=end;i+=step) { + arr.push(i) + } + } else { + for(i=start;i<=end;i+=step){ + arr.push(i); + } + } + return arr; } -function sum(array) { - // Your code here +function sum(arr){ + var sum = 0; + for(i=0;i