Completed functionality for paginationHelper in JS.