function Set() {
var items = {};
this.has = function(value) {
return value in items
}
this.add = function(value) {
if (!this.has(value)) {
items[value] = value;
return true
}
return false
}
this.remove = function() {
if (this.has(value)) {
delete items[value];
return true
}
return false
}
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 < values.length; i++) {
unionSet.add(values[i])
}
values = otherSet.values();
for (var i = 0; i < values.length; i++) {
unionSet.add(values[i])
}
return unionSet
}
this.intersection = function(otherSet) {
var intersection = new Set();
var values = this.values();
for (var i = 0; i < values.length; i++) {
if (otherSet.has(values[i])) {
intersection.add(values[i])
}
}
return intersection
}
this.difference = function(otherSet) {
var differece = new Set();
var values = this.values();
for (var i = 0; i < values.length; i++) {
if (!otherSet.has(values[i])) {
differece.add(values[i])
}
}
return differece
}
this.subSet = function(otherSet) {
var subSet = new Set();
if (this.size() > otherSet.size()) {
return false
}
var values = this.values();
for (var i = 0; values.length; i++) {
if (!otherSet.has(values[i])) {
return false
}
}
return true
}
}

  

最新文章

  1. Android编译过程中的碎碎念
  2. Javascript 中的严格模式
  3. 编写更好的jQuery代码
  4. 数据库SQL
  5. Lock较synchronized多出的特性
  6. 快乐的JS正则表达式(一)
  7. IE插件收集
  8. wrk 进程管理
  9. 五分钟打造自己的sql性能分析工具
  10. Csharp日常笔记
  11. &lt;转&gt;MySql 与Oracle区别
  12. .net web 点击链接在页面指定位置显示DIV的问题
  13. 国家语言,语言代码,locale id对应表
  14. Python之旅Day13 JavaScript与DOM部分
  15. Java实现三大简单排序算法
  16. Maven 学习 -- 目录
  17. 安恒7月赛wp
  18. Linux 各类设置、配置、使用技巧参考,Linux使用集锦
  19. SSH 报错解决方法记录汇总
  20. iOS 数据类型转换

热门文章

  1. thinkphp开发微信小程序后台流程
  2. 攻防世界--simple-unpack
  3. shell 脚本规范
  4. 测试微信小程序页面的生命周期
  5. 常见前端面试题JS部分
  6. UIWindow,UINavigationController,UIViewController
  7. linux性能分析工具Memory
  8. 07.Linux-CentOS系统库文件libaudit.so.1丢失问题
  9. vue,一路走来(4)--vuex
  10. java的任务