I need to create a sequence of numbers for pagination links, this sequence needs to be 7 numbers in length and start 3 numbers before the given number and end 3 numbers after the given number so if the current page was 17 the sequence would be,
14, 15, 16, 17, 18, 19, 20
I have this working with the following code,
const range = (start, stop) => Array.from({ length: (stop - start)}, (_, i) => start + (i*1));
But this code requires me to send the start and stop points, if I do this when the current page is <=3 I drop into minus numbers to get the sequence, when in reality would I would want is a sequence like,
3, 4, 5, 6, 7, 8, 9
so it's still 7 numbers in length, but because it couldn't do 3 preceeding number becaue it would start at 0 or lower it just did 7 proceeding numbers instead.
Is there a way in Jascript to work this stuff out, without a whole load of If/Else conditionals?