Guest User

Untitled

a guest
Nov 15th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. const pagination = (c, m) => {
  2. let current = c,
  3. last = m,
  4. delta = 2,
  5. left = current - delta,
  6. right = current + delta + 1,
  7. range = [],
  8. rangeWithDots = [],
  9. l;
  10.  
  11. for (let i = 1; i <= last; i++) {
  12. if (i == 1 || i == last || i >= left && i < right) {
  13. range.push(i);
  14. }
  15. }
  16.  
  17. for (let i of range) {
  18. if (l) {
  19. if (i - l === 2) {
  20. rangeWithDots.push(l + 1);
  21. } else if (i - l !== 1) {
  22. rangeWithDots.push('...');
  23. }
  24. }
  25. rangeWithDots.push(i);
  26. l = i;
  27. }
  28.  
  29. return rangeWithDots;
  30. }
Add Comment
Please, Sign In to add comment