Skip to content

Commit

Permalink
set intersection
Browse files Browse the repository at this point in the history
  • Loading branch information
Jay Gurav committed May 11, 2021
1 parent fa1bf9f commit cc6c499
Show file tree
Hide file tree
Showing 13 changed files with 5,452 additions and 183 deletions.
2,660 changes: 2,660 additions & 0 deletions docs/assets/css/main.css

Large diffs are not rendered by default.

Binary file added docs/assets/images/icons.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/images/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/images/widgets.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/images/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
248 changes: 248 additions & 0 deletions docs/assets/js/main.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/assets/js/search.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

94 changes: 94 additions & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<!doctype html>
<html class="default no-js">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>setutils</title>
<meta name="description" content="Documentation for setutils">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="assets/css/main.css">
<script async src="assets/js/search.js" id="search-script"></script>
</head>
<body>
<header>
<div class="tsd-page-toolbar">
<div class="container">
<div class="table-wrap">
<div class="table-cell" id="tsd-search" data-index="assets/js/search.json" data-base=".">
<div class="field">
<label for="tsd-search-field" class="tsd-widget search no-caption">Search</label>
<input id="tsd-search-field" type="text" />
</div>
<ul class="results">
<li class="state loading">Preparing search index...</li>
<li class="state failure">The search index is not available</li>
</ul>
<a href="index.html" class="title">setutils</a>
</div>
<div class="table-cell" id="tsd-widgets">
<div id="tsd-filter">
<a href="#" class="tsd-widget options no-caption" data-toggle="options">Options</a>
<div class="tsd-filter-group">
<div class="tsd-select" id="tsd-filter-visibility">
<span class="tsd-select-label">All</span>
<ul class="tsd-select-list">
<li data-value="public">Public</li>
<li data-value="protected">Public/Protected</li>
<li data-value="private" class="selected">All</li>
</ul>
</div>
<input type="checkbox" id="tsd-filter-inherited" checked />
<label class="tsd-widget" for="tsd-filter-inherited">Inherited</label>
<input type="checkbox" id="tsd-filter-externals" checked />
<label class="tsd-widget" for="tsd-filter-externals">Externals</label>
</div>
</div>
<a href="#" class="tsd-widget menu no-caption" data-toggle="menu">Menu</a>
</div>
</div>
</div>
</div>
<div class="tsd-page-title">
<div class="container">
<h1>setutils</h1>
</div>
</div>
</header>
<div class="container container-main">
<div class="row">
<div class="col-8 col-content">
<div class="tsd-panel tsd-typography">
</div>
</div>
<div class="col-4 col-menu menu-sticky-wrap menu-highlight">
<nav class="tsd-navigation primary">
<ul>
<li class=" ">
<a href="modules.html">Exports</a>
</li>
</ul>
</nav>
<nav class="tsd-navigation secondary menu-sticky">
<ul class="before-current">
<li class=" tsd-kind-property">
<a href="modules.html#default" class="tsd-kind-icon">default</a>
</li>
</ul>
</nav>
</div>
</div>
</div>
<footer class="with-border-bottom">
<div class="container">
<h2>Legend</h2>
<div class="tsd-legend-group">
</div>
</div>
</footer>
<div class="container tsd-generator">
<p>Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p>
</div>
<div class="overlay"></div>
<script src="assets/js/main.js"></script>
</body>
</html>
120 changes: 120 additions & 0 deletions docs/modules.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<!doctype html>
<html class="default no-js">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>setutils</title>
<meta name="description" content="Documentation for setutils">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="assets/css/main.css">
<script async src="assets/js/search.js" id="search-script"></script>
</head>
<body>
<header>
<div class="tsd-page-toolbar">
<div class="container">
<div class="table-wrap">
<div class="table-cell" id="tsd-search" data-index="assets/js/search.json" data-base=".">
<div class="field">
<label for="tsd-search-field" class="tsd-widget search no-caption">Search</label>
<input id="tsd-search-field" type="text" />
</div>
<ul class="results">
<li class="state loading">Preparing search index...</li>
<li class="state failure">The search index is not available</li>
</ul>
<a href="index.html" class="title">setutils</a>
</div>
<div class="table-cell" id="tsd-widgets">
<div id="tsd-filter">
<a href="#" class="tsd-widget options no-caption" data-toggle="options">Options</a>
<div class="tsd-filter-group">
<div class="tsd-select" id="tsd-filter-visibility">
<span class="tsd-select-label">All</span>
<ul class="tsd-select-list">
<li data-value="public">Public</li>
<li data-value="protected">Public/Protected</li>
<li data-value="private" class="selected">All</li>
</ul>
</div>
<input type="checkbox" id="tsd-filter-inherited" checked />
<label class="tsd-widget" for="tsd-filter-inherited">Inherited</label>
<input type="checkbox" id="tsd-filter-externals" checked />
<label class="tsd-widget" for="tsd-filter-externals">Externals</label>
</div>
</div>
<a href="#" class="tsd-widget menu no-caption" data-toggle="menu">Menu</a>
</div>
</div>
</div>
</div>
<div class="tsd-page-title">
<div class="container">
<h1>setutils</h1>
</div>
</div>
</header>
<div class="container container-main">
<div class="row">
<div class="col-8 col-content">
<section class="tsd-panel-group tsd-index-group">
<h2>Index</h2>
<section class="tsd-panel tsd-index-panel">
<div class="tsd-index-content">
<section class="tsd-index-section ">
<h3>Properties</h3>
<ul class="tsd-index-list">
<li class="tsd-kind-property"><a href="modules.html#default" class="tsd-kind-icon">default</a></li>
</ul>
</section>
</div>
</section>
</section>
<section class="tsd-panel-group tsd-member-group ">
<h2>Properties</h2>
<section class="tsd-panel tsd-member tsd-kind-property">
<a name="default" class="tsd-anchor"></a>
<h3>default</h3>
<div class="tsd-signature tsd-kind-icon">default<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-symbol">{}</span></div>
<aside class="tsd-sources">
</aside>
<div class="tsd-type-declaration">
<h4>Type declaration</h4>
<ul class="tsd-parameters">
</ul>
</div>
</section>
</section>
</div>
<div class="col-4 col-menu menu-sticky-wrap menu-highlight">
<nav class="tsd-navigation primary">
<ul>
<li class="current ">
<a href="modules.html">Exports</a>
</li>
</ul>
</nav>
<nav class="tsd-navigation secondary menu-sticky">
<ul class="before-current">
<li class=" tsd-kind-property">
<a href="modules.html#default" class="tsd-kind-icon">default</a>
</li>
</ul>
</nav>
</div>
</div>
</div>
<footer class="with-border-bottom">
<div class="container">
<h2>Legend</h2>
<div class="tsd-legend-group">
</div>
</div>
</footer>
<div class="container tsd-generator">
<p>Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p>
</div>
<div class="overlay"></div>
<script src="assets/js/main.js"></script>
</body>
</html>
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
"author": "Jay Gurav <[email protected]> (http://github.com/JayMGurav)",
"license": "MIT",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"test": "jest",
"doc": "typedoc --out docs ./src",
"build:dev": "webpack --watch --config ./buildConfigs/webpack.dev.js",
"build:prod": "webpack --config ./buildConfigs/webpack.prod.js",
"dev:start": "nodemon ./dist/main.bundle.js"
},
"devDependencies": {
"@microsoft/tsdoc": "^0.13.2",
"jest": "^26.6.3",
"nodemon": "^2.0.7",
"source-map-loader": "^2.0.1",
"ts-loader": "^9.1.2",
Expand Down
135 changes: 104 additions & 31 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,116 @@
// /**
// * setutils 1.0.0
// * (c) Jay Gurav 2021
// */
/**
* setutils 1.0.0
* (c) Jay Gurav 2021
*/


// declare global {
// interface Set<T> {
// union(sets:Set<any>[]): Set<any>;
// }
// }
declare global {
interface Set<T> {
isSuperSet(subSet:Set<any>): boolean;
isSubSet(superSet: Set<any>): boolean;
cartesianProduct(set: Set<any>): Set<any>;
union(...sets:Set<any>[]): Set<any>;
intersection(...sets:Set<any>[]): Set<any>;
symmetricDifference(...sets:Set<any>[]): Set<any>;
setDifference(...sets:Set<any>[]): Set<any>;
}
}


/**
* checks if a set is a superset of input set
*
* @param set - input set
* @returns boolean
*/
Set.prototype.isSuperSet = function(set:Set<any> ) :boolean {
return [...set].every(val => this.has(val));
}

// /**
// * @param {Set<any>[]} sets - A array of sets
// *
// * @return {Set<any>} Returns a union of all sets
// */
// Set.prototype.union = function(sets:Set<any>[] ) :Set<any> {
// return sets.reduce(function (acc: Set<any>, set: Set<any>) {
// return new Set([...acc, ...set]);
// }, new Set([...this]));
// }

// // const s = new Set();
/**
* checks if the passed set is subset
*
* @param set - Input set
* @returns boolean
*/
Set.prototype.isSubSet = function(set:Set<any> ) :boolean {
return [...this].every(val => set.has(val));
}

// // const y = s.un
// // const y = s.union([new Set([3,"43",5]), new Set([7,41,8])]);
/**
*
* Returns the union of passed sets
*
* @param ...sets
* @returns union set of all the passed sets
*/
Set.prototype.union = function(...sets:Set<any>[] ) :Set<any> {
return sets.reduce((acc: Set<any>, set: Set<any>) => {
return new Set([...acc, ...set]);
}, this);
}

// // console.log(y)
// export default {}

/**
* Returns the intersection of all the sets
*
* @param ...sets
* @returns Intersection of all the sets
*/
Set.prototype.intersection = function(...sets:Set<any>[] ) :Set<any> {
const arrOfSets = sets.concat(this)
const smallestSet = arrOfSets.reduce((acc, curr) => acc.size < curr.size ? acc : curr, this);
return new Set([...smallestSet].filter(val => arrOfSets.every((set) => set.has(val))));
}

import "./utilities";

const set1 = new Set([1, 2, 3, 4]);
const set2 = new Set([3, 4, 5, 6]);
const set3 = new Set([ 5, 6, 3, 4]);
// const set3 = new Set([7,8,9]);
/**
* returns symetric difference with all the input sets
*
* @param ...sets
* @returns symmetric difference of all the sets
*/
Set.prototype.symmetricDifference = function(...sets:Set<any>[] ) :Set<any> {
return sets.reduce((acc:Set<any>, curr:Set<any>) :Set<any> => {
for(let elem of curr){
if(acc.has(elem)){
acc.delete(elem);
}else{
acc.add(elem);
}
}
return acc;
}, this);
}

const y = set1.intersection(set2, set3)
console.log(y);

/**
* returns set difference with all the input sets
*
* @param ...sets
* @returns set difference of all the sets
*/
Set.prototype.setDifference = function(...sets:Set<any>[] ) :Set<any> {
const unionOfSets = new Set(sets.reduce((acc:any[], curr:Set<any>) => acc.concat([...curr]), []));
return new Set([...this].filter(val => !unionOfSets.has(val)));
}



/**
* returns the cartesian product with the input set
* @param set - input
* @returns cartesian product
*/
Set.prototype.cartesianProduct = function(set:Set<any>) :Set<any> {
return new Set([...this].reduce((acc, val) => {
let arr:any[] = [];
for(let elem of set){
arr.push([val, elem]);
}
return acc.concat(arr);
}, []))
}

export default {}
Loading

0 comments on commit cc6c499

Please sign in to comment.