Skip to content

Instantly share code, notes, and snippets.

@Luke-Rogerson
Last active May 1, 2018 05:52
Show Gist options
  • Save Luke-Rogerson/08274afefd9ef1090c8ed1c8f0ddfd4a to your computer and use it in GitHub Desktop.
Save Luke-Rogerson/08274afefd9ef1090c8ed1c8f0ddfd4a to your computer and use it in GitHub Desktop.
TheSumOfARange created by Luke_Rogerson - https://repl.it/@Luke_Rogerson/TheSumOfARange
// 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