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

Refactor find last methods #114

Merged
merged 3 commits into from
Jan 29, 2024

Conversation

wanglam
Copy link
Collaborator

@wanglam wanglam commented Jan 26, 2024

Description

Find last related methods was added in TC39, it can't be used in some old browsers. The FT for electron 94 in FT repo will be failed due to these methods. Refactor to reverse and find.

Issues Resolved

[List any issues this PR will resolve]

Check List

  • New functionality includes testing.
    • All tests pass, including unit test, integration test.
  • New functionality has user manual doc added.
  • Commits are signed per the DCO using --signoff.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Signed-off-by: Lin Wang <wonglam@amazon.com>
Signed-off-by: Lin Wang <wonglam@amazon.com>
@wanglam wanglam added backport 2.x Trigger the backport flow to 2.x Skip-Changelog labels Jan 26, 2024
Copy link

codecov bot commented Jan 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (e045d11) 95.31% compared to head (c8ceafa) 95.34%.
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #114      +/-   ##
==========================================
+ Coverage   95.31%   95.34%   +0.02%     
==========================================
  Files          47       48       +1     
  Lines        1260     1268       +8     
  Branches      304      306       +2     
==========================================
+ Hits         1201     1209       +8     
  Misses         57       57              
  Partials        2        2              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

const index = [...array].reverse().findIndex(predicate);
if (index === -1) {
return -1;
}
Copy link
Collaborator

@Hailong-am Hailong-am Jan 26, 2024

Choose a reason for hiding this comment

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

why don't just search from last element to first?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Is that means write a for loop to search from end to start?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, that sounds like more straightforward and no additional array copy and reverse

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Make sense, will update later.

Signed-off-by: Lin Wang <wonglam@amazon.com>
@wanglam wanglam merged commit e7b810e into opensearch-project:main Jan 29, 2024
10 checks passed
@wanglam wanglam deleted the refactor-find-last-methods branch January 29, 2024 06:54
opensearch-trigger-bot bot pushed a commit that referenced this pull request Jan 29, 2024
* refactor: replace findLast with find and reverse

Signed-off-by: Lin Wang <wonglam@amazon.com>

* refactor: replace Array.prototype.findLastIndex with findLastIndex

Signed-off-by: Lin Wang <wonglam@amazon.com>

* refactor findLastIndex with for loop

Signed-off-by: Lin Wang <wonglam@amazon.com>

---------

Signed-off-by: Lin Wang <wonglam@amazon.com>
(cherry picked from commit e7b810e)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
wanglam pushed a commit that referenced this pull request Jan 29, 2024
* refactor: replace findLast with find and reverse



* refactor: replace Array.prototype.findLastIndex with findLastIndex



* refactor findLastIndex with for loop



---------


(cherry picked from commit e7b810e)

Signed-off-by: Lin Wang <wonglam@amazon.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x Trigger the backport flow to 2.x Skip-Changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants