isSubset
Input two arrays arr1 and arr2, and return whether arr1 is subset of arr2.
Accepts a getter, which can be a field path of getByPath or a callback function, used to provide an identifier to distinguish elements.
Added in v0.1.0
Usage
ts
import { isSubset } from 'parsnip-kit'
const arr0 = [1, 2]
const arr1 = [1, 1, 2]
const arr2 = [1, 2, 3]
isSubset(arr0, arr2) // true
isSubset(arr1, arr2) // false
const getter = (product: Product, index: number, arr: Product[]) =>
`${product.id}-${index}`
const subset = [{ id: 'p1', name: 'Laptop', price: 1000 }]
const superset = [
{ id: 'p1', name: 'Laptop', price: 1000 },
{ id: 'p2', name: 'Mouse', price: 50 }
]
isSubset(subset, superset, getter) // trueAPI
Type Parameter
| Arg | Type | Description |
|---|---|---|
T | | The type of element of input arr |
Arguments
| Arg | Type | Optional | Default | Description |
|---|---|---|---|---|
arr1 | T[] | false | undefined | The candidate subset array |
arr2 | T[] | false | undefined | The superset array to check against |
getter | string | ((item: T, index: number, arr: T[]) => any) | true | undefined | Provide an identifier to distinguish the elements |
Returns
| Type |
|---|
boolean |