Skip to content

Instantly share code, notes, and snippets.

@qassim
Created May 17, 2016 19:43
Show Gist options
  • Save qassim/7947cacb29a7a319afc3289e5393c28c to your computer and use it in GitHub Desktop.
Save qassim/7947cacb29a7a319afc3289e5393c28c to your computer and use it in GitHub Desktop.
//Pagination logic
var pages = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
//var totalPages = pages.length;
var lastPage = false;
var firstPage = false;
// a(8);
function a(n) {
for (var i = 0; i < totalPages; i = i + 3) {
var slice = pages.slice(i, i + 3);
if (slice.indexOf(n) > -1) {
return slice;
}
}
}
b(a(5));
function b(n) {
var LastPages = a(pages.length);
var startPages = a(pages[0]);
if (n.sort().join(',') === startPages.sort().join(',')) {
firstPage = true;
} else if (n.sort().join(',') === LastPages.sort().join(',')) {
lastPage = true;
}
var output;
if (firstPage) {
output = '< ' + n + '... >';
} else if (lastPage) {
output = '< ...' + n + ' >';
} else {
output = '< ...' + n + '... >';
}
console.log(output);
console.log("Is first page? " + firstPage);
console.log("Is last page? " + lastPage);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment