Set()

This class contains all methods to simulate a SET data-structure

new Set()

Create a SET data-structure

Example
const { Set } = require('data-structures-algorithms-js');
const set = new Set();

Methods

clear()

Reset the SET data-structure

Example
const { Set } = require('data-structures-algorithms-js');
const set = new Set(); 

set.insert(15);

set.clear();

erase(element) → {Boolean}

Remove a element from the SET data-structure

Parameters:
Name Type Description
element *

Element passed to remove

Returns:
Boolean -

If element was removed from the SET

Example
const { Set } = require('data-structures-algorithms-js');
const set = new Set();

set.insert(25);
set.insert(3);

set.erase(3); //return true
set.erase(42); //return false;

find(Element) → {Boolean}

Find a specific element in the SET data-structure

Parameters:
Name Type Description
Element *

Element to find

Returns:
Boolean
Example
const { Set } = require('data-structures-algorithms-js');
const set = new Set(); 

set.find(5); //return false

insert(element) → {Boolean}

Add a element into the SET data-structure

Parameters:
Name Type Description
element *

Element passed to insert

Returns:
Boolean -

If element was added into the SET

Example
const { Set } = require('data-structures-algorithms-js');
const set = new set();

set.insert(2); //return true
set.insert(38); //return true
set.insert(2); //return false

isEmpty() → {Boolean}

Return if the SET data-structure is empty

Returns:
Boolean
Example
const { Set } = require('data-structures-algorithms-js');
const set = new Set(); 

set.isEmpty(); // return true;

set.insert(15);

set.isEmpty(); //return false;

size() → {Number}

Return the size of the SET data-structure

Returns:
Number -

The number of elements in SET

Example
const { Set } = require('data-structures-algorithms-js');
const set = new Set(); 

set.size(); // return 0;

set.insert(8);

set.size(); //return 1;

values() → {Array}

Return all elements in the SET data-structure

Returns:
Array -

Return an ordered Array

Example
const { Set } = require('data-structures-algorithms-js');
const set = new set(); 

set.insert(55);
set.insert(36);
set.insert(78);

set.values(); //return [36, 55, 78]