Skip to content

isSubset

Static Badge

2つの配列 arr1arr2 を入力し、arr1arr2 のサブセットであるかどうかを返します。

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) // true

API

Type Parameter

ArgTypeDescription
TT 入力配列の要素の型

Arguments

ArgTypeOptionalDefaultDescription
arr1T[]falseundefinedチェック対象のサブセット配列
arr2T[]falseundefinedチェック対象のスーパーセット配列
getterstring | ((item: T, index: number, arr: T[]) => any)trueundefined要素を区別するための識別子を提供します

Returns

Type
boolean