Advertisement

javascript集合(集合数据结构)

阅读量:

并集:通过将两个集合中的元素进行整合,形成一个包含所有成员的新集合

复制代码
 function Set() {

    
     this.dataStore = [];
    
     this.add = add;
    
     this.remove = remove;
    
     this.show = show;
    
     this.contains = contains;
    
  
    
     this.size = size;
    
     this.union = union;
    
     this.intersect = intersect;
    
     this.subset = subset;
    
     this.difference = difference;
    
  
    
 }
    
 //添加元素(不含相同元素)
    
 function add(data) {
    
     if (this.dataStore.indexOf(data) < 0) {
    
     this.dataStore.push(data);
    
     return true;
    
     } else {
    
     return

全部评论 (0)

还没有任何评论哟~