function set () {
This.datastore=[];
This.add=add;
This.remove.remove;
This.size=size;
This.union=union;
This.intersect=intersect;
This.subset=subset;
This.difference=difference;
This.show=show;
}
function Add (data) {
if (this.dataStore.indexOf (data) <0) {//The uniqueness of the collection
This.dataSource.push (data);
}
else{
return false;
}
}
function remove (data) {
var pos=this.datastore.indexof (data);
if (pos>-1)
{
This.dataStore.splice (pos,1);
}
Else
{
return false;
}
}
Function Show () {
return this.datastore;
}
Function Union (SET)
{
var tempset=new set;
for (Var i=0;i<this.datastore.length;i++)
{
Tempset.add (This.datastore[i]);
}
for (Var i=0;i<set.datastore.length;++i)
{
if (!tempset.contains (Set.datastore[i]))
{
Tempset.dataStore.push (Set.datastore[i]);
}
}
return tempset;
}
function intersect (SET)
{
var tempset=new set ();
for (Var i=0;i<this.datastore.length;i++)
{
if (Set.contains (This.datastore[i])) {
Tempset.add (Set.datastore[i]);
}
}
return tempset;
}
function subset (SET) {
if (This.size () >set.size ()) {
return false;
}
else{
for (var key in This.datastore)
{
if (!set.contains (key)) {
return false;
}
}
}
return true;
}
function size () {
return this.dataStore.length;
}
function difference (SET)
{
var tem,pset=new set ();
for (var key in This.datastore)
{
if (!set.contains (key))
{
Tempset.add (key);
}
}
return tempset;
}
JavaScript Implementation Collection