How to simplify the condition for the paginator?
-
https://repl.it/@fomenkogregory/Paginator-5#src/App .js
I created such a paginator, how to simplify the condition without changing the behavior? Help.JavaScript Elliot Small, Feb 12, 2019 -
Let's put in separate variables the conditions that determine whether it is necessary to show groups of buttons that ...
// ...прилегают к первой кнопке
const showAfterFirst = currentPage < 5;
// ...прилегают к последней кнопке
const showBeforeLast = currentPage > totalPages - 4;
Accordingly, the conditions for displaying ellipsis after / before the first / last buttons will be reversed values:! ShowAfterFirst
and! ShowBeforeLast
. To show the center button group, both base conditions must be false:! (ShowAfterFirst || showBeforeLast)
.
https://jsfiddle.net/0sjgrcxu/1/Anonymous
1 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!