Created
January 29, 2014 15:59
-
-
Save slopeofhope81/8691043 to your computer and use it in GitHub Desktop.
//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.
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, step) { | |
var arr = []; | |
if (arguments[2] == undefined) { | |
for (var i = start; i <= end; i++) | |
arr.push(i); | |
} else { | |
for (var i = start; i <= end; i += step) | |
arr.push(i); | |
} | |
return arr; | |
} | |
document.write(range(1, 10, 2)); | |
// |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment