Generic paging algorithm
var truncate = pageCount &gt; (7 + (surroundingPageLinkSize * 2));
  if (!truncate) {
    for (var i = 1; i &lt;= pageCount; i++) {
      buttons.push(i);
    }
  }
  else {
    var truncateEnd = currentPage &lt; (1 + (surroundingPageLinkSize * 2)),
        truncateBoth = (pageCount - (surroundingPageLinkSize * 2)) &gt; currentPage &amp;&amp; currentPage &gt; (surroundingPageLinkSize * 2);

    if (truncateEnd) {
      for (var j = 1; j &lt; (4 + (surroundingPageLinkSize * 2)); j++) {
        buttons.push(j);
      }
      appendTruncateButtons(buttons, pageCount);
    }
    else if (truncateBoth) {
      prependTruncateButtons(buttons);
      for (var k = (currentPage - surroundingPageLinkSize); k &lt;= (currentPage + surroundingPageLinkSize); k++) {
        buttons.push(k);
      }
      appendTruncateButtons(buttons, pageCount);
    }
    else { // Truncate start
      prependTruncateButtons(buttons);
      for (var l = pageCount - (2 + (surroundingPageLinkSize * 2)); l &lt;= pageCount; l++) {
        buttons.push(l);
      }
    }
  }



Note that all of these cases have essentially the same for loop.  

  var start = 1,
      end = pageCount;

  if (currentPage &gt; surroundingPageLinkSize * 2) {
      start = currentPage - surroundingPageLinkSize;
      prependTruncateButtons(buttons);
  }

  if (currentPage &lt; pageCount - surroundingPageLinkSize * 2 - 2) {
      end = currentPage + surroundingPageLinkSize;
  }

  for (var i = start; i &lt;= end; i++) {
      buttons.push(i);
  }

  if (end &lt; pageCount) {
      appendTruncateButtons(buttons);
  }


Now we call it just once, only changing the parameters.  

We also only call the prepend and append methods once each.  You could even pull those into this method if you wanted, as they are no longer repeated code.  

I also like that this gets rid of the three single use Boolean variables.  Since they weren't reused, they don't seem necessary.  

I'm not sure if the output is an exact match for what you had originally, but it should give the same kind of display.  

I didn't change it here, but consider changing buttons to pages or even pageNumbers.  These are the pages that you want to make links or buttons that go there.  But they aren't buttons yet.