-
Notifications
You must be signed in to change notification settings - Fork 23
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
Refactor find last methods #114
Conversation
Signed-off-by: Lin Wang <wonglam@amazon.com>
Signed-off-by: Lin Wang <wonglam@amazon.com>
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. |
const index = [...array].reverse().findIndex(predicate); | ||
if (index === -1) { | ||
return -1; | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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>
* 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>
* 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>
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
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.