Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ISSUE: Total Pages Calculation Fix for project RMTDEV #7

Open
Dev-Dipesh opened this issue Apr 12, 2024 · 1 comment
Open

ISSUE: Total Pages Calculation Fix for project RMTDEV #7

Dev-Dipesh opened this issue Apr 12, 2024 · 1 comment

Comments

@Dev-Dipesh
Copy link

Dev-Dipesh commented Apr 12, 2024

Project: rmtdev
Video Number: 158
Video Title: Finish Pagination (Derived State)

ISSUE: In the video, we're calculating the total pages without using Math.ceil().

FIX:
Math.ceil is important here because we want to round up to the nearest whole number. For example, if we have 15 jobs and we want to display 7 jobs per page, we need 3 pages.

15 / 7 = 2.14 // Simple division will set total pages to 2, which will lead to missing the last job

Math.ceil(2.14) = 3 // We need 3 pages to show all 15 jobs
@Rope-a-dope
Copy link

Rope-a-dope commented Jun 4, 2024

The code is actually correct. You can double check. Because the number totalPages is by is actually not a integer. This is JavaScript, not Java.

 const totalPages = totalJobs / RESULTS_PER_PAGE; 

In Java, we would use the following expression.

int totalPages = (totalJobs + RESULTS_PER_PAGE - 1) / RESULTS_PER_PAGE;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants