Created
September 17, 2014 02:16
-
-
Save lmullen/4bc56e2caca7e8e99e88 to your computer and use it in GitHub Desktop.
Sum and range
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
<body> | |
<script src="script.js"></script> | |
</body> |
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
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