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

fix: Low version browsers do not have the at function #1870

Merged
merged 1 commit into from
Dec 18, 2024

Conversation

shaohuzhang1
Copy link
Contributor

fix: Low version browsers do not have the at function

Copy link

f2c-ci-robot bot commented Dec 18, 2024

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Copy link

f2c-ci-robot bot commented Dec 18, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@@ -138,7 +138,7 @@ export class ChatRecordManage {
) {
return this.write_node_info
}
const run_node = this.node_list.filter((item) => item.buffer.length > 0 || !item.is_end).at(0)
const run_node = this.node_list.filter((item) => item.buffer.length > 0 || !item.is_end)[0]

if (run_node) {
const index = this.node_list.indexOf(run_node)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The provided code is mostly clean, but there's one line that can be optimized. Here’s the relevant part:

const run_node = this.node_list.filter((item) => item.buffer.length > 0 || !item.is_end)[0];

This line uses filter with an array containing exactly one element, which can be written more directly using bracket notation:

const run_node = this.node_list[0] || null;

However, since you're checking both conditions (buffer.length > 0 and !item.is_end), you should maintain the original logic while simplifying it a bit by removing redundant steps:

const node_length_greater_than_zero = !!this.node_list.filter(x => x.buffer.length > 0).length;
const node_isnt_finished = !!this.node_list.find(x => !x.is_end);

if (node_length_greater_than_zero && node_isnt_finished) {
    // Your logic here
}

But if you want to keep everything concise and efficient without unnecessary nesting, you could just use:

const next_runnable = this.node_list.filter(item => item.buffer.length > 0 || !item.is_end)?.shift();

If none of these options meet your requirements, please let me know how I can assist further.

@shaohuzhang1 shaohuzhang1 merged commit bcdc2fd into main Dec 18, 2024
4 of 5 checks passed
@shaohuzhang1 shaohuzhang1 deleted the pr@main@fix_at_function branch December 18, 2024 10:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant