Skip to content

Instantly share code, notes, and snippets.

@slopeofhope81
Created January 29, 2014 15:59
Show Gist options
  • Save slopeofhope81/8691043 to your computer and use it in GitHub Desktop.
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.
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