Skip to main content
added 63 characters in body
Source Link
Roman
  • 2.8k
  • 11
  • 23
  • on the first to 5. button : 1, 2, 3, 4, 5 ... 50
  • on button between 6. to 50.: 1, ... 6, [7], 8, ..., 50
  • on the last button  47. to 50.: 1, ... 46, 47, 48, 49[49], [50]50
function buildPagination(current) {
    if (current < 6) {
        const pagination =  [
            button(1),
            button(2),
            button(3),
            button(4),
            button(5),
            placeholder(),
            button(last),
        ];
        pagination[current].disable();
        return pagination;
    }

    if (current ===> (last - 4)) {
        returnconst pagination = [
            button(1),
            placeholder(),
            button(last - 4),
            button(last - 3),
            button(last - 2),
            button(last - 1),
            button(last),
        ];
        pagination[current].disable(),;
        ];return pagination;
    }

    return [
        button(1),
        placeholder(),
        button(current - 1),
        button(current).disable(),
        button(current + 1),
        placeholder(),
        button(last),
    ];
}
  • on the first to 5. button : 1, 2, 3, 4, 5 ... 50
  • on button between 6. to 50.: 1, ... 6, [7], 8, ..., 50
  • on the last button  : 1, ... 46, 47, 48, 49, [50]
function buildPagination(current) {
    if (current < 6) {
        const pagination =  [
            button(1),
            button(2),
            button(3),
            button(4),
            button(5),
            placeholder(),
            button(last),
        ];
        pagination[current].disable();
        return pagination;
    }

    if (current === last) {
        return [
            button(1),
            placeholder(),
            button(last - 4),
            button(last - 3),
            button(last - 2),
            button(last - 1),
            button(last).disable(),
        ];
    }

    return [
        button(1),
        placeholder(),
        button(current - 1),
        button(current).disable(),
        button(current + 1),
        placeholder(),
        button(last),
    ];
}
  • on the first to 5. button : 1, 2, 3, 4, 5 ... 50
  • on button between 6. to 50.: 1, ... 6, [7], 8, ..., 50
  • on button 47. to 50.: 1, ... 47, 48, [49], 50
function buildPagination(current) {
    if (current < 6) {
        const pagination =  [
            button(1),
            button(2),
            button(3),
            button(4),
            button(5),
            placeholder(),
            button(last),
        ];
        pagination[current].disable();
        return pagination;
    }

    if (current > (last - 4)) {
        const pagination = [
            button(1),
            placeholder(),
            button(last - 4),
            button(last - 3),
            button(last - 2),
            button(last - 1),
            button(last),
        ];
        pagination[current].disable();
        return pagination;
    }

    return [
        button(1),
        placeholder(),
        button(current - 1),
        button(current).disable(),
        button(current + 1),
        placeholder(),
        button(last),
    ];
}
deleted 10 characters in body
Source Link
Roman
  • 2.8k
  • 11
  • 23
else if (pageSize >= 6... && i == 6) {
    buttons.push(add(i, false, ..., ...));
}
else if (pageSize >= 6 && i == 6) {
    buttons.push(add(i, false, ..., ...));
}
else if (... && i == 6) {
    buttons.push(add(i, false, ..., ...));
}
deleted 21 characters in body
Source Link
Roman
  • 2.8k
  • 11
  • 23
  • getButtonData letslet me imply that it returns information about one button
  • getButtonDataByPage the same like getButtonData
  • add implies that something gets added to a collection

you have someSome conditions in you code that have hate thisfollow the semantic: of condition ? true : false which is the same as condition. For instance:

Let's analyze getButtonData butand the same will be apply to getButtonDataByPage.

After simplify all branches we can getthe simplification:

whichwhere i == 1 can be further simplified tohave its own branch:

and since the branch body of i < 6 and i === pageSize are the same:

  1. on the first to 5. button : 1, 2, 3, 4, 5 ... 50
  2. on button between 6. to 50.: 1, ... 6, [7], 8, ..., 50
  3. on the last button : 1, ... 46, 47, 48, 49, [50]
  • on the first to 5. button : 1, 2, 3, 4, 5 ... 50
  • on button between 6. to 50.: 1, ... 6, [7], 8, ..., 50
  • on the last button : 1, ... 46, 47, 48, 49, [50]
  • getButtonData lets me imply that it returns information about one button
  • getButtonDataByPage the same like getButtonData
  • add implies that something gets added to a collection

you have some conditions in you code that have hate this semantic: condition ? true : false which is the same as condition. For instance:

Let's analyze getButtonData but the same will be apply to getButtonDataByPage.

After simplify all branches we can get:

which can be further simplified to:

and branch i < 6 and i === pageSize are the same:

  1. on the first to 5. button : 1, 2, 3, 4, 5 ... 50
  2. on button between 6. to 50.: 1, ... 6, [7], 8, ..., 50
  3. on the last button : 1, ... 46, 47, 48, 49, [50]
  • getButtonData let me imply that it returns information about one button
  • getButtonDataByPage the same like getButtonData
  • add implies that something gets added to a collection

Some conditions follow the semantic of condition ? true : false which is the same as condition. For instance:

Let's analyze getButtonData and the same will be apply to getButtonDataByPage.

After the simplification:

where i == 1 can have its own branch:

and since the branch body of i < 6 and i === pageSize are the same:

  • on the first to 5. button : 1, 2, 3, 4, 5 ... 50
  • on button between 6. to 50.: 1, ... 6, [7], 8, ..., 50
  • on the last button : 1, ... 46, 47, 48, 49, [50]
Source Link
Roman
  • 2.8k
  • 11
  • 23
Loading