Created
July 17, 2023 08:39
-
-
Save codeallday31/a4754d59520c19fdfe26c6a41df8d19f 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
/** | |
* Emulates python's range() built-in. Returns an array of integers, counting | |
* up (or down) from start to end. Note that the range returned is up to, but | |
* NOT INCLUDING, end. | |
*. | |
* @param start integer from which to start counting. If the end parameter is | |
* not provided, this value is considered the end and start will | |
* be zero. | |
* @param end integer to which to count. If omitted, the function will count | |
* up from zero to the value of the start parameter. Note that | |
* the array returned will count up to but will not include this | |
* value. | |
* @return an array of consecutive integers. | |
*/ | |
function range(start, end) { | |
if (arguments.length == 1) { | |
var end = start; | |
start = 0; | |
} | |
var r = []; | |
if (start < end) { | |
while (start != end) | |
r.push(start++); | |
} else { | |
while (start != end) | |
r.push(start--); | |
} | |
return r; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment