Last active
December 27, 2021 06:41
-
-
Save hoyangtsai/c027418942ba823d2ced1d740ec5971c to your computer and use it in GitHub Desktop.
javascript range array function #snippet #jsUtil
This file contains hidden or 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, edge, step) { | |
// If only one number was passed in make it the edge and 0 the start. | |
if (arguments.length == 1) { | |
edge = start; | |
start = 0; | |
} | |
// Validate the edge and step numbers. | |
edge = edge || 0; | |
step = step || 1; | |
// Create the array of numbers, stopping befor the edge. | |
for (var ret = []; (edge - start) * step > 0; start += step) { | |
ret.push(start); | |
} | |
return ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
From Chris West's blog his post