new Set()
Creates a SET data-structure
Example
const { Set } = require('data-structures-algorithms-js');
const set = new Set();
Methods
-
clear()
-
Resets the SET data-structure
Example
const { Set } = require('data-structures-algorithms-js'); const set = new Set(); set.insert(15); set.clear();
-
erase(element) → {Boolean}
-
Removes 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); //returns true set.erase(42); //returns false;
-
find(Element) → {Boolean}
-
Finds a specific element in the SET data-structure
Parameters:
Name Type Description Element
* Element to find
Returns:
BooleanExample
const { Set } = require('data-structures-algorithms-js'); const set = new Set(); set.find(5); //returns false
-
insert(element) → {Boolean}
-
Adds an element to 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); //returns true set.insert(38); //returns true set.insert(2); //returns false
-
isEmpty() → {Boolean}
-
Returns if the SET data-structure is empty
Returns:
BooleanExample
const { Set } = require('data-structures-algorithms-js'); const set = new Set(); set.isEmpty(); // returns true; set.insert(15); set.isEmpty(); //returns false;
-
size() → {Number}
-
Returns 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(); // returns 0; set.insert(8); set.size(); //returns 1;
-
values() → {Array}
-
Returns all elements in the SET data-structure
Returns:
Array -Returns 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(); //returns [36, 55, 78]