Created
August 2, 2017 16:36
-
-
Save davidbalbert/44625268c76a684589a0c99650edb5b5 to your computer and use it in GitHub Desktop.
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, stop, step = 1) { | |
| if (Math.sign(stop-start) !== Math.sign(step) || step === 0) { | |
| return []; | |
| } | |
| let nums = []; | |
| if (step > 0) { | |
| for (let i = start; i <= stop; i += step) { | |
| nums.push(i); | |
| } | |
| } else { | |
| for (let i = start; i >= stop; i += step) { | |
| nums.push(i); | |
| } | |
| } | |
| return nums; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment