首页 > 其他 > 详细

数据结构_集合

时间:2020-02-24 12:16:59      阅读:72      评论:0      收藏:0      [点我收藏+]
//集合,不允许重复,无序
  class Gather {
    constructor () {
      this.items = {}
    }
    add (prop) {
      if (this.isHas(prop)) return false
      else this.items[prop] = undefined
      return true

    }
    remove (prop) {
      if (!this.isHas(prop)) return false
      delete this.items[prop]
      return true
    }
    //判断属性是否存在集合中
    isHas (prop) {
      return this.items.hasOwnProperty(prop)
    }
    clear () {
      this.items = {}
      return true
    }
    size () {
      return Object.keys(this.items).length
    }
    values () {
      return Object.keys(this.items)
    }
  }

 

数据结构_集合

原文:https://www.cnblogs.com/JunLan/p/12355888.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!