Advertisement
Guest User

Untitled

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