Skip to main content
Code Review

Return to Question

edited tags
Link
200_success
  • 145.6k
  • 22
  • 190
  • 479
deleted 4 characters in body
Source Link
Pimgd
  • 22.5k
  • 5
  • 68
  • 144

I implemented a function for pager link creation, it looks like this:

function createPagerObject(pageUri, page, totPages) {
 const MAX_PAGES_IN_PAGER = 6;
 // for the first three pages the starting would be 1
 let pageNumber = Math.sign(page - 3) > 0 ? page - 3 : 1;
 let pager = [];
 for(let i = 0; i < MAX_PAGES_IN_PAGER; i++){
 pager.push({
 "page": pageNumber,
 "href": pageUri.replace("list-" + page, "list-" + pageNumber),
 "type": pageNumber == page ? "current" : pageNumber > page ? "next" : "prev"
 });
 pageNumber++;
 if(pageNumber > totPages) {
 break;
 }
 }
 return pager;
}

the code is self explanatory, but the idea is to create an Array of objects with the structure:

page --> the page number
href --> the link to the destination page
type --> "current", "next" or "prev" depending on the current page

page → the page number
href → the link to the destination page
type → "current", "next" or "prev" depending on the current page

having as input the current page uriURI, the current page number and the number of pages.

The question is "it could be improved", because it seems not so clean to me.

I implemented a function for pager link creation, it looks like this:

function createPagerObject(pageUri, page, totPages) {
 const MAX_PAGES_IN_PAGER = 6;
 // for the first three pages the starting would be 1
 let pageNumber = Math.sign(page - 3) > 0 ? page - 3 : 1;
 let pager = [];
 for(let i = 0; i < MAX_PAGES_IN_PAGER; i++){
 pager.push({
 "page": pageNumber,
 "href": pageUri.replace("list-" + page, "list-" + pageNumber),
 "type": pageNumber == page ? "current" : pageNumber > page ? "next" : "prev"
 });
 pageNumber++;
 if(pageNumber > totPages) {
 break;
 }
 }
 return pager;
}

the code is self explanatory, but the idea is to create an Array of objects with the structure:

page --> the page number
href --> the link to the destination page
type --> "current", "next" or "prev" depending on the current page

having as input the current page uri, the current page number and the number of pages.

The question is "it could be improved", because it seems not so clean to me.

I implemented a function for pager link creation, it looks like this:

function createPagerObject(pageUri, page, totPages) {
 const MAX_PAGES_IN_PAGER = 6;
 // for the first three pages the starting would be 1
 let pageNumber = Math.sign(page - 3) > 0 ? page - 3 : 1;
 let pager = [];
 for(let i = 0; i < MAX_PAGES_IN_PAGER; i++){
 pager.push({
 "page": pageNumber,
 "href": pageUri.replace("list-" + page, "list-" + pageNumber),
 "type": pageNumber == page ? "current" : pageNumber > page ? "next" : "prev"
 });
 pageNumber++;
 if(pageNumber > totPages) {
 break;
 }
 }
 return pager;
}

the code is self explanatory, but the idea is to create an Array of objects with the structure:

page → the page number
href → the link to the destination page
type → "current", "next" or "prev" depending on the current page

having as input the current page URI, the current page number and the number of pages.

The question is "it could be improved", because it seems not so clean to me.

Source Link

Javascript pager logic

I implemented a function for pager link creation, it looks like this:

function createPagerObject(pageUri, page, totPages) {
 const MAX_PAGES_IN_PAGER = 6;
 // for the first three pages the starting would be 1
 let pageNumber = Math.sign(page - 3) > 0 ? page - 3 : 1;
 let pager = [];
 for(let i = 0; i < MAX_PAGES_IN_PAGER; i++){
 pager.push({
 "page": pageNumber,
 "href": pageUri.replace("list-" + page, "list-" + pageNumber),
 "type": pageNumber == page ? "current" : pageNumber > page ? "next" : "prev"
 });
 pageNumber++;
 if(pageNumber > totPages) {
 break;
 }
 }
 return pager;
}

the code is self explanatory, but the idea is to create an Array of objects with the structure:

page --> the page number
href --> the link to the destination page
type --> "current", "next" or "prev" depending on the current page

having as input the current page uri, the current page number and the number of pages.

The question is "it could be improved", because it seems not so clean to me.

lang-js

AltStyle によって変換されたページ (->オリジナル) /