realset-implementation

1.0.1 • Public • Published

RealSet extends Set

RealSet is a class that extends the standard Set implementation in JavaScript with intersect and union methods.

Getting Started

The file realset.js contains example usage.

Example usage

const realSetInstance1 = new RealSet([]);
const realSetInstance2 = new RealSet([]);
for(let i=0;i<10;i+=1){
    if(i<=5)realSetInstance1.add(i);
    if(i>=5)realSetInstance2.add(i);
}
let intersectSet = realSetInstance1.intersect(realSetInstance2);
let unionSet = realSetInstance1.union(realSetInstance2);

console.log(`Intersect: ${Array.from(intersectSet.values())}`);
//Logs Intersect: 5

console.log(`Union: ${Array.from(unionSet.values())}`);
//Logs Union: 0,1,2,3,4,5,6,7,8,9

//Update instance following mutation in parents
realSetInstance1.add(6);
intersectSet=intersectSet.refresh();
console.log(`Intersect: ${Array.from(intersectSet.values())}`);
//Logs Intersect: 5,6

License

This project is licensed under the Apache License 2.0 - see the LICENSE.md file for details

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i realset-implementation

      Weekly Downloads

      0

      Version

      1.0.1

      License

      Apache-2.0

      Unpacked Size

      14.3 kB

      Total Files

      6

      Last publish

      Collaborators

      • cssimsek