• Stars
    star
    521
  • Rank 84,483 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 6 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Set() as it should be.

zet

version build status codecov install size

JavaScript Set() as it should be.

ECMAScript 6 sets have no methods for computing the union (โˆช), intersection (โˆฉ) or difference (โŠ–). Zet is an extension of ES6 Set and comes with all its functionality included with extra set logic. The API is similar to how sets work in Python.

Features

Additions to the default ECMAScript 6 set

  • Union (โˆช)
  • Intersection (โˆฉ)
  • Difference/subtract (-)
  • Symmetric difference (โŠ–)
  • Subset (โŠ†)
  • Superset (โŠ‡)
  • Map
  • Filter
  • Reduce

Additionally, this module is delivered as:

  • ES Module: dist/zet.mjs
  • CommonJS: dist/zet.js
  • UMD: dist/zet.umd.js

Install

$ npm install --save zet

Usage

import Zet from 'zet';

let a = new Zet([1, 2, 3]);
let b = new Zet([3, 4, 5]);
let c = new Zet([2, 3, 4]);

Zet.union(a, b);
//=> [Zet] {1, 2, 3, 4, 5}

a.union(b, c);
//=> [Zet] {1, 2, 3, 4, 5}

a.intersection(b);
//=> [Zet] {3}

a.symmetricDifference(c);
//=> [Zet] {1, 4}

a.subset(b);
//=> false

a.filter(i => i % 2);
//=> [Zet] {1, 3}

API

Zet([iterable])

Returns:Zet

Returns the Zet instance.

Zet extends Set() and inherit all its functionality, like has(), size() etc.

Zet.union(...sets) โˆช

Returns:zet

Static variadic function that return a new set with elements from all other sets.

sets

Type: Zet|Set

Two or more sets of type Zet or Set.

Zet.intersection(...sets) โˆฉ

Returns:zet

Static variadic function that return a new set with elements common to this and all other sets.

sets

Type: Zet|Set

Two or more sets of type Zet or Set.

Zet.difference(...sets) - or \

Returns:zet

Returns the difference between two or more sets. The order of the sets matters. Sets are differentiated against the first argument/set.

sets

Type: Zet|Set

Two or more sets of type Zet or Set.

Zet.symmetricDifference(setA, setB) โŠ– or โˆ†

Returns:zet

Static function that return a new set with elements in either setA or setB but not both.

setA

Type: Zet|Set

Set A of type Zet or Set.

setB

Type: Zet|Set

Set B of type Zet or Set.

Zet.subset(setA, setB)

Returns: Boolean

Test whether every element in setB is in setA.

setA

Type: Zet|Set

Set of type Zet or Set.

setB

Type: Zet|Set

Set of type Zet or Set.

Zet.superset(setA, setB)

Returns: Boolean

Test whether every element in setA is in setB.

setA

Type: Zet|Set

Set of type Zet or Set.

setB

Type: Zet|Set

Set of type Zet or Set.

map(set, func)

Returns: Zet|Set

Creates a set with the results of calling the provided function on every element.

set

Type: Zet|Set

Set of type Zet or Set.

func

Type: Function

Function that produces an element of the new set.

filter(set, func)

Returns: Zet|Set

Creates a set with all elements that pass the test implemented by the provided function.

set

Type: Zet|Set It is the set going to be examined.

func

Type: Function

It is a predicate, to test each element of the set.

reduce(set, func, initializer)

Returns: Number

Reduces the set to a single value, by executing the provided function for each element in the set (from left-to-right).

set

Type: Zet|Set

Set of type Zet or Set.

func

Type: Function

Function to be executed for each element in the set.

initializer

Type: Number

Optional. A value to be passed to the function as the initial value.

Instance Methods

union(...sets) โˆช

Returns:zet

Variadic method that return a new set with elements from this and all other sets.

sets

Type: Zet|Set

One or more sets of type Zet or Set.

intersection(...sets) โˆฉ

Returns:zet

Variadic method that return a new set with elements common to this and all other sets.

sets

Type: Zet|Set

One or more sets of type Zet or Set.

difference(...sets) - or \

Returns:zet

Variadic method tht return a new set with elements in this that are not in the other sets.

sets

Type: Zet|Set

One or more sets of type Zet or Set.

symmetricDifference(other) โŠ– or โˆ†

Returns:zet

Method that return a new set with elements in either this or other but not both. This is also known as xor.

other

Type: Zet|Set

Set of type Zet or Set.

subset(other)

Returns: Boolean

Test whether every element in the set is in other.

other

Type: Zet|Set

Set of type Zet or Set.

superset(other)

Returns: Boolean

Test whether every element in other is in the set.

other

Type: Zet|Set

Set of type Zet or Set.

map(func)

Returns: Zet|Set

Creates a set with the results of calling the provided function on every element.

func

Type: Function

Function that produces an element of the new set.

filter(func)

Returns: Zet|Set

Creates a set with all elements that pass the test implemented by the provided function.

func

Type: Function

It is a predicate, to test each element of the set.

reduce(func, initializer)

Returns: Number

Reduces the set to a single value, by executing the provided function for each element in the set (from left-to-right).

func

Type: Function

Function to be executed for each element in the set.

initializer

Type: Number

Optional. A value to be passed to the function as the initial value.

License

MIT ยฉ Terkel Gjervig

More Repositories

1

awesome-creative-coding

Creative Coding: Generative Art, Data visualization, Interaction Design, Resources.
HTML
12,228
star
2

prompts

โฏ Lightweight, beautiful and user-friendly interactive prompts
JavaScript
8,805
star
3

ramme

Unofficial Instagram Desktop App.
JavaScript
3,319
star
4

tiny-glob

Super tiny and ~350% faster alternative to node-glob
JavaScript
849
star
5

sqliterally

Lightweight SQL query builder
JavaScript
263
star
6

terkelg

A website inside an SVG, inside an image, inside HTML, inside markdown, inside a GitHub readme.md.
TypeScript
223
star
7

facon

Tiny utility (365B) to create DOM elements with manner.
JavaScript
222
star
8

deakins

๐ŸŽฅ Small Canvas 2D Camera
TypeScript
135
star
9

math

Math snippets with graphic programming in mind.
113
star
10

zuckerberg.smile

๐Ÿค– Control Mark Zuckerbergs smile property
JavaScript
89
star
11

skaler

A (329B) client-side image resizer.
JavaScript
88
star
12

workshy

A small (376B) lazy function scheduler for a butter smooth main thread.
JavaScript
80
star
13

math-toolbox

Lightweight and modular math toolbox
JavaScript
76
star
14

globrex

Glob to regular expression with support for extended globs.
JavaScript
67
star
15

cantinflas

Tiny mustache-like template engine in ~50 LOC.
JavaScript
65
star
16

sisteransi

ANSI escape codes for some terminal swag.
JavaScript
58
star
17

eliminate

Delete files and directories without all the bullshit.
JavaScript
52
star
18

terkel.com-2016

My Personal website. Build with Vue and ThreeJS.
JavaScript
40
star
19

powerwalker

๐ŸƒWalk directories recursively.
JavaScript
28
star
20

hent

A small utility to fetch remote files into buffers
JavaScript
23
star
21

npm-scripts-as-build-tool

Nuggets on how to use NPM Scripts as your build tool. You don't need Grunt or Gulp
21
star
22

cursor-travel

๐Ÿ“ Measure how far your cursor travels.
Swift
19
star
23

favorite-awesomeness

A tiny collection of my favorite awesomelists
18
star
24

shrinktome

๐Ÿ“˜Shrink facebook by 5% every 10th second. You're welcome!
JavaScript
16
star
25

stopgap

Easily create/remove temporary directories.
JavaScript
16
star
26

simultan

Simultaneously run an async function on any iterable with limited concurrency
JavaScript
15
star
27

cursormuseum

A very brief history of pointing devices
CSS
14
star
28

mkdirplz

Make directories recursively -plz ๐Ÿ™
JavaScript
13
star
29

antedate

A tiny pre-renderer for client side applications.
JavaScript
13
star
30

webpack-starter

'Just Add Water' Webpack 2, babel and glslify gourmet mix.
JavaScript
13
star
31

starter

No tooling starter because simplicity is the ultimate sophistication.
CSS
13
star
32

1d

๐ŸฅžMake multi-dimensional arrays as flat as a pancake.
JavaScript
11
star
33

utters

Small (257B) promise wrapper for SpeechSynthesisUtterance
JavaScript
11
star
34

globalyzer

Detect and extract the static part of a glob string.
JavaScript
10
star
35

vimrc

I heard you like escape rooms?
Vim Script
10
star
36

foldersstructure

macOS Automator workflow to scaffold my project directory structure.
10
star
37

threejs-create

Create a generic three.js application for quick prototyping
JavaScript
9
star
38

exclamation

Holy Stratosphere, Robin exclamationsโ—
JavaScript
7
star
39

invisible

The Invisible Game: Huckle buckle beanstalk
JavaScript
6
star
40

brolly

Internet of Things Umbrella Game.
JavaScript
6
star
41

yeezify

Instantly change all images on any given webpage to Kanye West.
JavaScript
6
star
42

IMDb-Runtimes

A simple Google Chrome extension to convert runtimes on IMDb to hours and minutes.
JavaScript
4
star
43

judgedbycover

A Twitter bot that judge books based on their cover.
JavaScript
3
star
44

dmjx-intro

Website for DMJX freshers' weekend
HTML
1
star
45

terkeliknibe

I created this website after nearly four months of apartment searching
SCSS
1
star