Last active
May 1, 2018 05:52
-
-
Save Luke-Rogerson/08274afefd9ef1090c8ed1c8f0ddfd4a to your computer and use it in GitHub Desktop.
TheSumOfARange created by Luke_Rogerson - https://repl.it/@Luke_Rogerson/TheSumOfARange
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Eloquent Javascript, Chapter 4, Coding Challenge #1 | |
/* Write a range function that takes two arguments, start and end, and returns an array containing all the numbers from start up to (and including) end. */ | |
function range (start, end, step) { | |
let rangeArray = []; | |
for (let i = start; i <= end; i += step) { | |
rangeArray.push(i); | |
} | |
return rangeArray; | |
} | |
function sum (arrayOfNumbers) { | |
let total = 0; | |
for (let j = 0; j <= arrayOfNumbers.length; j++) { | |
total += j; | |
} | |
return (total); | |
} | |
range(1, 10, 3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment