How to simplify the condition for the paginator?

  • 0 .js

    I created such a paginator, how to simplify the condition without changing the behavior? Help.
    JavaScript Elliot Small, Feb 12, 2019

  • 1 Answers
  • 0
    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) .

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!