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(dropWhile): dropWhile returns the whole array when every element does not match the predicate #49

Merged
merged 3 commits into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: bug in dropWhile
  • Loading branch information
changwoolab committed Jun 14, 2024
commit eda581d029c0f414e5a27e084bfd1203574230af
2 changes: 2 additions & 0 deletions src/array/dropWhile.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ describe('dropWhile', () => {
},
{ id: 3, enabled: false },
]);

expect(dropWhile([1, 2, 3], x => x < 4)).toEqual([]);
});
});
2 changes: 1 addition & 1 deletion src/array/dropWhile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
*/
export function dropWhile<T>(arr: readonly T[], canContinueDropping: (item: T) => boolean): T[] {
const dropEndIndex = arr.findIndex(item => !canContinueDropping(item));
return arr.slice(dropEndIndex);
return dropEndIndex === -1 ? [] : arr.slice(dropEndIndex);
raon0211 marked this conversation as resolved.
Show resolved Hide resolved
}