Skip to content

Instantly share code, notes, and snippets.

@lmullen
Created September 17, 2014 02:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lmullen/4bc56e2caca7e8e99e88 to your computer and use it in GitHub Desktop.
Save lmullen/4bc56e2caca7e8e99e88 to your computer and use it in GitHub Desktop.
Sum and range
<body>
<script src="script.js"></script>
</body>
function range(start, end) {
var array = []
for (start; start <= end; start++) {
array.push(start);
}
return array;
}
function sum(numbers) {
var total = 0;
for (var i = 0; i < numbers.length; i++) {
total += numbers[i];
}
return total;
}
function rangeStep(start, end, step) {
var array = []
for (start; start <= end; start += step) {
array.push(start);
}
return array;
}
console.log(sum(range(1, 10)));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment