-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Lexus Drumgold <[email protected]>
- Loading branch information
1 parent
409ca18
commit 1fb621e
Showing
3 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* @file Unit Tests - pull | ||
* @module tutils/utils/tests/unit/pull | ||
*/ | ||
|
||
import testSubject from '../pull' | ||
|
||
describe('unit:utils/pull', () => { | ||
it('should return array without items in drop', () => { | ||
// Arrange | ||
const array: number[] = [0, 1, 2, 3, 4, 5] | ||
const drop: number[] = [3, 4, 5] | ||
|
||
// Expect | ||
expect(testSubject(array, drop, null)).to.deep.equal([0, 1, 2]) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* @file Utilities - pull | ||
* @module tutils/utils/pull | ||
*/ | ||
|
||
import type { Fn, IndexSignature, Nilable, NumberString } from '#src/types' | ||
import includes from './includes' | ||
import select from './select' | ||
|
||
/** | ||
* Removes all items in `drop` from `array` without modifying `array`. | ||
* | ||
* @template T - Array item type | ||
* @template K - Identity key type | ||
* | ||
* @param {ReadonlyArray<T>} array - Array to evaluate | ||
* @param {ReadonlyArray<T>} drop - Items to remove | ||
* @param {Nilable<Fn<[T], K>>} [identity] - Identity key function | ||
* @return {T[]} New array without items in `drop` | ||
*/ | ||
function pull<T, K extends IndexSignature = NumberString>( | ||
array: readonly T[], | ||
drop: readonly T[], | ||
identity?: Nilable<Fn<[T], K>> | ||
): T[] { | ||
return select(array, (item: T): boolean => !includes(drop, item, identity)) | ||
} | ||
|
||
export default pull |