Skip to content

Instantly share code, notes, and snippets.

@alexpilugin
Last active July 9, 2017 12:18
Show Gist options
  • Save alexpilugin/bf909e1e0bb7ac725fec12c95dfeaa95 to your computer and use it in GitHub Desktop.
Save alexpilugin/bf909e1e0bb7ac725fec12c95dfeaa95 to your computer and use it in GitHub Desktop.
//returns array which includes all numbers from start to end (included)
function range(start, end, step) {
if(step < 0) step = -step;
if(!step) step = 1;
if(end == undefined) {
end = start;
start = 0;
}
var result = [];
var len = end - start;
var counter = start;
if (end > start) {
while (counter <= end) {
result.push(counter);
counter += step;
}
} else if (end < start){
while (counter >= end) {
result.push(counter);
counter -= step;
}
} else {
result.push(start);
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment