Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions src/compat/array/pullAll.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { pullAll } from './pullAll';

describe('pullAll', () => {
function pull(array: any[], values: any[]) {

Check warning on line 5 in src/compat/array/pullAll.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 5 in src/compat/array/pullAll.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
return pullAll(array, values);
}

Expand Down Expand Up @@ -53,4 +53,10 @@
expect(result).toBe(array);
expect(array).toEqual([1, 2, 3]);
});

it('should return the array as is when `values` is `null` or `undefined`', () => {
const array = [1, 2, 3];
expect(pullAll(array, null as any)).toBe(array);

Check warning on line 59 in src/compat/array/pullAll.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
expect(pullAll(array, undefined)).toBe(array);
});
});
5 changes: 5 additions & 0 deletions src/compat/array/pullAll.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { pull as pullToolkit } from '../../array/pull.ts';
import { isNil } from '../../predicate/isNil.ts';
import type { MutableList } from '../_internal/MutableList.d.ts';
import type { RejectReadonly } from '../_internal/RejectReadonly.d.ts';

Expand Down Expand Up @@ -38,7 +39,7 @@
* console.log(array);
* // => [1, 1]
*/
export function pullAll<L extends MutableList<any>>(array: RejectReadonly<L>, values?: ArrayLike<L[0]>): L;

Check warning on line 42 in src/compat/array/pullAll.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

/**
* Removes all specified values from an array.
Expand All @@ -57,5 +58,9 @@
* console.log(numbers); // [1, 3, 5]
*/
export function pullAll<T>(arr: T[], valuesToRemove: ArrayLike<T> = []): T[] {
if (isNil(valuesToRemove)) {
return arr;
}

return pullToolkit(arr, Array.from(valuesToRemove));
}