Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // int array range [start, stop], step = 1
- let myIntArray = Array(stop).fill(start).map((x, y) => x + y)
- // Array(12).fill(1).map((x, y) => x + y)
- // [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
- // int array range [start, stop), step = {step}
- const rangeExclusive = (start, stop, step = 1) =>
- Array(Math.ceil((stop - start) / step)).fill(start).map((x, y) => x + y * step)
- let myIntArray = rangeExclusive(3, 27, 2)
- // [3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25]
- // int array range [start, stop], step = {step}
- const rangeInclusive = (start, stop, step = 1) =>
- Array(Math.ceil((stop - start) / step) + 1).fill(start).map((x, y) => x + y * step)
- let myIntArray = rangeInclusive(3, 27, 2)
- // [3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement