I'm trying to implement a function which takes three arguments(min, max, step)and generates a range of integers from min to max, with the step. The first integer is the minimum value, the second is the maximum of the range and the third is the step.
Here is an example of what it should look like: generateRange(2, 10, 2) should return array of [2,4,6,8,10].
I'm using the splice method to remove any existing elements in the array that are greater than the max argument.
function generateRange(min, max, step) { var arr = []; var count = min; for (var i = 0; i < max / step; i++) { arr[i] = count; count = count + step; arr[i] > max ? arr.splice(i, 1) : arr[i]; } return arr; } console.log(generateRange(2, 10, 2)); Whenever I console.log my result I get a bunch of commas after the last item...so it looks like this: [2,4,6,8,10, , , , ]
It doesn't appear to be deleting the items. What am I missing? Thanks!
ifstatement.