6.16 Exercise: interval table
So now we've learned a lot about arrays, it's time to do some exercises. Here is our first exercise. I want you to write a function called arrayFromRange. This function has to take two parameters min and max and this is how we can use this function. So when we are in the program we get an array we have numbers from 1 to 4 like for example. So when we run this program we get an array, and in this array we have numbers from 1 to 4, as you can see here. We can also pass a negative number here, like for example -10 to -4. So we'll have an array like this. Here, we first need to create an empty array, which we'll call output and set it to an empty array. Now we need a for loop to generate numbers between min and max. So, for let i = min. As long as i is less than or equal to max, we will increment i and then push that i into our array. So output. Push of i. And finally, we return this output. Now let's test this. So record the changes with -10 and -4, these are the numbers we get, if you pass a positive number like 1 to 4, this is the output, if the maximum value you provide is less than the minimum, you get an empty array.