When RANGE > 2 we will access indices i and i + RANGE - 1 which will end up outside the range of the array
because we are not changing the for loop end condition.
Example:
RANGE = 3
length = 4
for loop i goes to length - 2 = 4 - 2 = 2
i = 2
i + RANGE - 1 = i + 3 - 1 = i + 2 = 2 + 2 = 4
...sortedReleaseDates[4], // gives a index out of range exception
Fix
for (let i = 0; i < sortedReleaseDates.length - RANGE + 1; i++) {
Bug
There is a index out of range bug here: https://github.com/github-tools/github-release-notes/blob/8c5affc496f7b787fa0793ce3f7b812354d5679f/lib/src/Gren.js#L1096-L1101 The for loop index goes all the way to
length - 2
(2nd last element) and we are accessing indicesi
andi + 1
in the loop. This only works whenRANGE = 2
.When
RANGE > 2
we will access indicesi
andi + RANGE - 1
which will end up outside the range of the array because we are not changing the for loop end condition. Example:Fix