generate an array of numbers between a max and a min value with an interval between 2 values

You can figure out how many items should be in the result by dividing the difference between max and min by the interval, then create the array with Array.from, using the mapper’s index to figure out how much to add to the min for each value of the array:

const min = 1000,
  max = 10000,
  interval = 1000;

const length = (max - min) / interval + 1;
const arr = Array.from({ length }, (_, i) => min + i * interval);

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top