-
Notifications
You must be signed in to change notification settings - Fork 494
fix(find, findLast): simplify logic by removing unnecessary checks #1453
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
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Pull Request Overview
This PR refactors the find
function to simplify its logic by removing unnecessary type checks and streamlining array handling. The changes improve code maintainability while preserving functionality.
- Removed redundant
typeof doesMatch === 'function'
check sinceiteratee()
always returns a function - Simplified array slicing logic by removing conditional check that was no longer needed
- Improved test coverage as shown in the before/after screenshots
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1453 +/- ##
==========================================
- Coverage 99.90% 99.90% -0.01%
==========================================
Files 468 468
Lines 4439 4437 -2
Branches 1309 1307 -2
==========================================
- Hits 4435 4433 -2
Misses 4 4 🚀 New features to boost your workflow:
|
Summary
This PR simplifies the
find
function implementation by removing unnecessary type checks and simplifying array handling logic.This fix improves test coverage.
There is no test for the case where there is no predicate, so the coverage is not 100%. However, someone else worked on this part, so I did not modify it separately!
Changes
typeof doesMatch === 'function'
check sinceiteratee()
always returns a functionArray.isArray(source) ? source.slice(fromIndex) : Object.values(source).slice(fromIndex)
tosource.slice(fromIndex)
since at that point in the code,source
is guaranteed to be an arrayAdditional
The
findLast
function also had the same issue and was fixed. This function also did not have a test for the case where there is no predicate, so the coverage is not 100%, but someone else worked on it :) #1450