@abozhilov/set-utils 中文文档教程

发布于 3年前 浏览 20 项目主页 更新于 3年前

@abozhilov/set-utils - v1.0.0

用于使用内置 Set 的实用程序库。

用 TypeScript 编写。

Installation

npm

    npm install @abozhilov/set-utils

yarn

    yarn add @abozhilov/set-utils

Table of contents

Functions

Functions

isSubset

isSubset<Т>(setA, setB): boolean

检查setA 是否是 setB 的子集。 该操作由 setA ⊆ setB 表示。

  assert.equal(
      isSubset(new Set([1, 2]), new Set([1, 2, 3])),
      true
  );

Type parameters

Name
Т

Parameters

NameType
setASet<Т>
setBSet<Т>

Returns

boolean

Defined in

index.ts:12


isStrictSubset

isStrictSubset<Т>(setA, setB): boolean

检查 setA 是否是 setB 的严格(适当)子集。 该操作由 setA ⊂ setB 表示。

 assert.equal(
     isStrictSubset(new Set([1, 2]), new Set([1, 2, 3])),
     true
 );
 assert.equal(
     isStrictSubset(new Set([1, 2]), new Set([1, 2])),
     false
 );

Type parameters

Name
Т

Parameters

NameType
setASet<Т>
setBSet<Т>

Returns

boolean

Defined in

index.ts:41


isSuperset

isSuperset<T>(setA, setB): boolean

检查 setA 是否是 setB 的超集。 该操作由 setA ⊇ setB 表示。

  assert.equal(
      isSuperset(new Set([1, 2, 3]), new Set([1, 2])),
      true
  );

Type parameters

Name
T

Parameters

NameType
setASet<T>
setBSet<T>

Returns

boolean

Defined in

index.ts:60


isStrictSuperset

isStrictSuperset<T>(setA, setB): boolean

检查 setA 是否是 setB 的严格(正确)超集。 该操作由 setA ⊃ setB 表示。

 assert.equal(
     isStrictSuperset(new Set([1, 2, 3]), new Set([1, 2])),
     true
 );
 assert.equal(
     isStrictSuperset(new Set([1, 2]), new Set([1, 2])),
     false
 );

Type parameters

Name
T

Parameters

NameType
setASet<T>
setBSet<T>

Returns

boolean

Defined in

index.ts:82


union

union<T>(setA, setB, ...restSets): Set<T>;

返回包含每个集合中所有元素的新集合。 该操作由 setA ⋃ setB 表示。

   assert.deepEqual(
       union(new Set([1, 2]), new Set([3, 4])),
       new Set([1, 2, 3, 4])
   );
   assert.deepEqual(
       union(new Set([1, 2]), new Set([3, 4]), new Set([5, 6])),
       new Set([1, 2, 3, 4, 5, 6])
   );

Type parameters

Name
T

Parameters

NameType
setASet<T>
setBSet<T>
...restSetsSet<T>[]

Returns

设置<T>

Defined in

index.ts:105


intersect

相交<T>(setA, setB, …sets): Set<T>;

返回一个新集合,其中包含 setA 的所有元素,这些元素也属于 setB。 该操作由 setA ⋂ setB 表示。

   assert.deepEqual(
       intersect(new Set([1, 2, 3]), new Set([2, 3, 4])),
       new Set([2, 3])
   );
   assert.deepEqual(
       intersect(new Set([1, 2, 3]), new Set([2, 3, 4]), new Set([2, 3, 5])),
       new Set([2, 3])
   );

Type parameters

Name
T

Parameters

NameType
setASet<T>
setBSet<T>
...setsSet<T>[]

Returns

设置<T>

Defined in

index.ts:139


difference

差异<T>(setA, setB, ...sets): Set<T>;

返回一个新集合,其中包含 setA 中不属于 setB 的所有元素。 该操作由 setA \ setB 表示。

   assert.deepEqual(
       difference(new Set([1, 2, 3]), new Set([3, 4, 5])),
       new Set([1, 2])
   );
   assert.deepEqual(
       difference(new Set([1, 2, 3, 4, 5]), new Set([3, 4]), new Set([4, 5])),
       new Set([1, 2])
   );

Type parameters

Name
T

Parameters

NameType
setASet<T>
setBSet<T>
...setsSet<T>[]

Returns

设置<T>

Defined in

index.ts:178


symmetricDifference

symmetricDifference<T>(setA, setB, ...集合): Set<T>;

返回一个新集合,其中包含 setA 中不属于 setB 的所有元素,反之亦然。 该操作由 setA ∆ setB 表示。

   assert.deepEqual(
       symmetricDifference(new Set([1, 2, 3]), new Set([3, 4, 5])),
       new Set([1, 2, 4, 5])
   );
   assert.deepEqual(
       symmetricDifference(new Set([1, 2, 3, 4]), new Set([3, 4, 5, 6]), new Set([4, 5, 7])),
       new Set([1, 2, 6, 7])
   );

Type parameters

Name
T

Parameters

NameType
setASet<T>
setBSet<T>
...setsSet<T>[]

Returns

设置<T>

Defined in

index.ts:217

@abozhilov/set-utils - v1.0.0

Utility library for working with the built-in Set.

Written in TypeScript.

Installation

npm

    npm install @abozhilov/set-utils

yarn

    yarn add @abozhilov/set-utils

Table of contents

Functions

Functions

isSubset

isSubset<Т>(setA, setB): boolean

Checks whether setA is a subset of setB. The operation is denoted by setA ⊆ setB.

  assert.equal(
      isSubset(new Set([1, 2]), new Set([1, 2, 3])),
      true
  );

Type parameters

Name
Т

Parameters

NameType
setASet<Т>
setBSet<Т>

Returns

boolean

Defined in

index.ts:12


isStrictSubset

isStrictSubset<Т>(setA, setB): boolean

Checks whether setA is a strict (proper) subset of setB. The operation is denoted by setA ⊂ setB.

 assert.equal(
     isStrictSubset(new Set([1, 2]), new Set([1, 2, 3])),
     true
 );
 assert.equal(
     isStrictSubset(new Set([1, 2]), new Set([1, 2])),
     false
 );

Type parameters

Name
Т

Parameters

NameType
setASet<Т>
setBSet<Т>

Returns

boolean

Defined in

index.ts:41


isSuperset

isSuperset<T>(setA, setB): boolean

Checks whether setA is a superset of setB. The operation is denoted by setA ⊇ setB.

  assert.equal(
      isSuperset(new Set([1, 2, 3]), new Set([1, 2])),
      true
  );

Type parameters

Name
T

Parameters

NameType
setASet<T>
setBSet<T>

Returns

boolean

Defined in

index.ts:60


isStrictSuperset

isStrictSuperset<T>(setA, setB): boolean

Checks whether setA is a strict (proper) superset of setB. The operation is denoted by setA ⊃ setB.

 assert.equal(
     isStrictSuperset(new Set([1, 2, 3]), new Set([1, 2])),
     true
 );
 assert.equal(
     isStrictSuperset(new Set([1, 2]), new Set([1, 2])),
     false
 );

Type parameters

Name
T

Parameters

NameType
setASet<T>
setBSet<T>

Returns

boolean

Defined in

index.ts:82


union

union<T>(setA, setB, …restSets): Set<T>

Returns new set which contains all elements from each set. The operation is denoted by setA ⋃ setB.

   assert.deepEqual(
       union(new Set([1, 2]), new Set([3, 4])),
       new Set([1, 2, 3, 4])
   );
   assert.deepEqual(
       union(new Set([1, 2]), new Set([3, 4]), new Set([5, 6])),
       new Set([1, 2, 3, 4, 5, 6])
   );

Type parameters

Name
T

Parameters

NameType
setASet<T>
setBSet<T>
...restSetsSet<T>[]

Returns

Set<T>

Defined in

index.ts:105


intersect

intersect<T>(setA, setB, …sets): Set<T>

Returns a new set with all elements of setA that also belongs to setB. The operation is denoted by setA ⋂ setB.

   assert.deepEqual(
       intersect(new Set([1, 2, 3]), new Set([2, 3, 4])),
       new Set([2, 3])
   );
   assert.deepEqual(
       intersect(new Set([1, 2, 3]), new Set([2, 3, 4]), new Set([2, 3, 5])),
       new Set([2, 3])
   );

Type parameters

Name
T

Parameters

NameType
setASet<T>
setBSet<T>
...setsSet<T>[]

Returns

Set<T>

Defined in

index.ts:139


difference

difference<T>(setA, setB, …sets): Set<T>

Returns a new set with all elements of setA that not belongs to setB. The operation is denoted by setA \ setB.

   assert.deepEqual(
       difference(new Set([1, 2, 3]), new Set([3, 4, 5])),
       new Set([1, 2])
   );
   assert.deepEqual(
       difference(new Set([1, 2, 3, 4, 5]), new Set([3, 4]), new Set([4, 5])),
       new Set([1, 2])
   );

Type parameters

Name
T

Parameters

NameType
setASet<T>
setBSet<T>
...setsSet<T>[]

Returns

Set<T>

Defined in

index.ts:178


symmetricDifference

symmetricDifference<T>(setA, setB, …sets): Set<T>

Returns a new set with all elements of setA that not belongs to setB and vice versa. The operation is denoted by setA ∆ setB.

   assert.deepEqual(
       symmetricDifference(new Set([1, 2, 3]), new Set([3, 4, 5])),
       new Set([1, 2, 4, 5])
   );
   assert.deepEqual(
       symmetricDifference(new Set([1, 2, 3, 4]), new Set([3, 4, 5, 6]), new Set([4, 5, 7])),
       new Set([1, 2, 6, 7])
   );

Type parameters

Name
T

Parameters

NameType
setASet<T>
setBSet<T>
...setsSet<T>[]

Returns

Set<T>

Defined in

index.ts:217

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文