From 6f064e121a2201b7be167693b1afb3295a07a672 Mon Sep 17 00:00:00 2001 From: onebuntoyou Date: Fri, 1 Sep 2017 10:11:05 -0400 Subject: [PATCH 1/2] Here's what I've completed --- chapter04.js | 92 +++++++++++++++++++++++++++++++++++++++++----------- chapter05.js | 11 +++++++ 2 files changed, 84 insertions(+), 19 deletions(-) diff --git a/chapter04.js b/chapter04.js index 12f6ef0..a82b79f 100644 --- a/chapter04.js +++ b/chapter04.js @@ -9,42 +9,96 @@ // 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 Date: Fri, 8 Sep 2017 12:04:18 -0400 Subject: [PATCH 2/2] completed ch4, all tests pass --- chapter04.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/chapter04.js b/chapter04.js index a82b79f..46094d9 100644 --- a/chapter04.js +++ b/chapter04.js @@ -30,7 +30,7 @@ function sum(arr){ return sum; } -// Pr(blem 2: Reversing an Array +// Problem 2: Reversing an Array function reverseArray(arr) { var rev = []; for(i=0;i