Skip to content

Commit

Permalink
fixing-readme
Browse files Browse the repository at this point in the history
  • Loading branch information
drhodes committed Apr 23, 2010
1 parent 2ee5324 commit 2e72059
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
32 changes: 32 additions & 0 deletions README.md
@@ -0,0 +1,32 @@
A Set data type with the following methods.

+ add
+ clear
+ copy
+ contains
+ difference
+ differenceUpdate
+ foreach
+ intersection
+ intersectionUpdate
+ isDisjoint
+ isSubset
+ isSuperset
+ remove
+ size
+ symmetricDifference
+ union
+ unionUpdate
+ fromArray
+ toArray

example:
var set1 = new Set()
var set2 = new Set()
- set1.add(1).add(2).add(3)
- set2.add(3).add(4).add(5)
-
- set1.union(set2) => Set<1, 2, 3, 4, 5>
- set1.intersection(set2) => Set<3>
-
- see tests.js for more examples;
17 changes: 16 additions & 1 deletion set.js
Expand Up @@ -29,9 +29,10 @@
+ remove
+ size
+ symmetricDifference
// symmetricDifferenceUpdate
+ union
+ unionUpdate
+ fromArray
+ toArray
*/

Set = function(){
Expand All @@ -47,6 +48,20 @@ Set.prototype.add = function(val){
return this;
}

Set.prototype.fromArray = function(arr){
for (var el in arr){
this.add(el);
}
}

Set.prototype.toArray = function(){
var arr = [];
for (var el in this.store){
arr.push(el);
}
return arr;
}

Set.prototype.clear = function(){
// removes all elements from the set.
this.store = {};
Expand Down

0 comments on commit 2e72059

Please sign in to comment.