Last active
July 9, 2017 12:18
-
-
Save alexpilugin/bf909e1e0bb7ac725fec12c95dfeaa95 to your computer and use it in GitHub Desktop.
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
//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