/** * 集合 */ function Set() { var items = {}; this.has = function(value){ return items.hasOwnProperty(value); }; this.add = function(value){ if (!this.has(value)){ items[value] = value; return true; } return false; }; this.remove = function(value){ if (this.has(value)){ delete items[value]; return true; } return false; }; this.clear = function(){ items = {}; }; this.size = function(){ return Object.keys(items).length; }; this.values = function(){ return Object.keys(items); }; // 并集 this.union = function(otherSet){ var unionSet = new Set(); var values = this.values(); for (var i=0; i otherSet.size()){ return false; } else { var values = this.values(); for (var i=0; i