Giter Site home page Giter Site logo

set's Introduction

@datastrucures-js/set

build:? npm npm npm

elements data type: number, string, boolean, null, undefined.

Usage

const setFn = require('@datastructures-js/set');
const set = setFn();

API

.add(element)

adds an element to the set.

set.add('A');
set.add('B');
set.add('C');
set.add('D');

.isEmpty()

checks if the set is empty.

console.log(set.isEmpty()); // false

.contains(element)

checks if the set contains an element

console.log(set.contains('C')); // true

.remove(element)

removes an element from the set.

set.remove('C');
console.log(set.contains('C')); // false

.size()

returns the number of elements in the set.

console.log(set.size()); // 3

.union(set)

unions the set with another set and returns the resulting set.

const set2 = ds.set();
set2.add('A');
set2.add('E');
set2.add('F');
const unionSet = set.union(set2); // unionSet contains A, B, D, E, F

.intersect(set)

intersects the set with another set and returns the resulting set.

const set2 = ds.set();
set2.add('A');
set2.add('E');
set2.add('F');
// set contains A, B, D
const intersectSet = set.intersect(set2); // intersectSet contains A

.diff(set)

returns the diff set between the set and another set.

const set2 = ds.set();
set2.add('A');
set2.add('E');
set2.add('F');
// set contains A, B, D
const diffSet = set.diff(set2); // diffSet contains B, D

.isSubsetOf(set)

checks if the set is a subset of another set

const s1 = ds.set();
s1.add('B');
s1.add('G');
s1.add('D');

const s2 = ds.set();
s2.add('A');
s2.add('G');
s2.add('B');
s2.add('G');
s2.add('D');

console.log(s2.isSubsetOf(s1)); // false
console.log(s1.isSubsetOf(s2)); // true

.isSupersetOf(set)

checks if the set is a subset of another set

const s1 = ds.set();
s1.add('B');
s1.add('G');
s1.add('D');

const s2 = ds.set();
s2.add('A');
s2.add('G');
s2.add('B');
s2.add('G');
s2.add('D');

console.log(s2.isSupersetOf(s1)); // true
console.log(s1.isSupersetOf(s2)); // true

.toArray()

converts the set to an array.

console.log(set.toArray()); // ['A', 'B', 'D']

.clear()

clears the set

set.clear(); // set is empty
console.log(set.size()); // 0  

Build

grunt build

License

The MIT License. Full License is here

set's People

Contributors

eyas-ranjous avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.