zoukankan      html  css  js  c++  java
  • JavaScript Set

    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
    	}
    }
    

      

  • 相关阅读:
    技能的切实掌握 必须动手
    sqlite 网址
    android视频教程
    Windows Azure
    mysql 存储过程 获取统计结果
    “道家”幸福生活的组成
    [文摘20110724]徐鹤宁 语录
    eclipse swt
    mysq 存储过程 插入测试数据
    WPF 视频教程
  • 原文地址:https://www.cnblogs.com/shidengyun/p/5122595.html
Copyright © 2011-2022 走看看