isSubset
2つの配列 arr1 と arr2 を入力し、arr1 が arr2 のサブセットであるかどうかを返します。
getter を受け付けます。これは getByPath のフィールドパスまたはコールバック関数で、要素を区別するための識別子を提供するために使用されます。
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 | | T 入力配列の要素の型 |
Arguments
| Arg | Type | Optional | Default | Description |
|---|---|---|---|---|
arr1 | T[] | false | undefined | チェック対象のサブセット配列 |
arr2 | T[] | false | undefined | チェック対象のスーパーセット配列 |
getter | string | ((item: T, index: number, arr: T[]) => any) | true | undefined | 要素を区別するための識別子を提供します |
Returns
| Type |
|---|
boolean |