mirror of
https://github.com/toss/es-toolkit.git
synced 2024-11-28 03:34:26 +03:00
fix(dropWhile): dropWhile
returns the whole array when every element does not match the predicate (#49)
* fix: bug in dropWhile * test: adds testcase for dropRightWhile * Update src/array/dropWhile.ts --------- Co-authored-by: Sojin Park <raon0211@gmail.com>
This commit is contained in:
parent
74ceaf47ec
commit
212f9709ee
@ -21,5 +21,7 @@ describe('dropRightWhile', () => {
|
||||
enabled: true,
|
||||
},
|
||||
]);
|
||||
|
||||
expect(dropRightWhile([1, 2, 3], x => x < 4)).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
@ -18,5 +18,7 @@ describe('dropWhile', () => {
|
||||
},
|
||||
{ id: 3, enabled: false },
|
||||
]);
|
||||
|
||||
expect(dropWhile([1, 2, 3], x => x < 4)).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
@ -17,5 +17,9 @@
|
||||
*/
|
||||
export function dropWhile<T>(arr: readonly T[], canContinueDropping: (item: T) => boolean): T[] {
|
||||
const dropEndIndex = arr.findIndex(item => !canContinueDropping(item));
|
||||
if (dropEndIndex === -1) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return arr.slice(dropEndIndex);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user