Created
January 31, 2019 19:47
-
-
Save jportella93/2b7a749c4b2fee1e9e6ea7c7e8205932 to your computer and use it in GitHub Desktop.
Create a range between to numbers in array form, with optional steps.
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
const range = (b, e = (b + (b = 0)), s = 1) => | |
Array.from({ length: (e - b) / s + 1 }, (v, i) => i * s + b); | |
// range(beggining, end, step) | |
// range(10) === [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] | |
// range(-5, 5) === [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5] | |
// range(-10, 10, 5) === [-10, -5, 0, 5, 10] | |
// range(10, 5) === [] | |
// range(10, 5, -1) === [10, 9, 8, 7, 6, 5] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment