by
29
9
379k
6
Top 1% !
Popular
Pearl of Wisdom
Nice
Useful
Easy-to-find
Specified
MultiPlatform
Pattern
Popularity: 2331st place
Languagejavascript
LicenseMIT_X11

set.js...  its my "Set", it runs this code-block

Full on structure type implimentation of a Set
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/221222/set-js-----its-my--Set---it-runs-this-co?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
// Set.... hut-1, hut-2, hike! function Set() { this.dStr = []; this.size = size; this.unionOf = unionOf; this.contains = contains; this.subSet = subSet; this.getDiff = getDiff; this.removeItem = removeItem; this.intersection = intersection; this.addItem = addItem; this.show = show; } function show() { return "[" + this.dStr + "]"; } function size() { return this.dStr.length; } function addItem(dta) { if (this.dStr.indexOf(dta) < 0) { this.dStr.push(dta); return true; } else { return false; } } function removeItem(dta) { var pstn = this.dStr.indexOf(dta); if (pstn > -1) { this.dStr.splice(pstn, 1); return true; } else { return false; } } function contains(dta) { if (this.dStr.indexOf(dta) > -1) { return true; } else { return false; } } function unionOf(set) { var tmp = new Set(), i = 0; for (;i < this.dStr.length; ++i) { tmp.add(this.dStr[i]); } i = 0; for (;i < set.dStr.length; ++i) { if (!tmp.contains(set.dStr[i])) { tmp.dStr.push(set.dStr[i]); } } return tmp; } function intersection(set) { var tSet = new Set(); for (var i = 0; i < this.dStr.length; ++i) { if (set.contains(this.dStr[i])) { tSet.add(this.dStr[i]); } } return tmp; } function subSet(set) { if (this.size() > set.size()) { return false; } else { for each (var m in this.dStr) { if (!set.contains(m)) { return false; } } } return true; } i = 0; function difference(set) { var tmp = new Set(); for (;i < this.dStor.length; ++i) { if (!set.contains(this.dStor[i])) { tmp.add(this.dStor[i]); } } return tmp; }
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus