• js:数据结构笔记6--字典


    Dictionary类的基础是数组不是对象;字典的主要用途是通过键取值;

    基本定义:

    function Dictionary() {
       this.dataStore = new Array();
       this.add = add;
       this.find = find;
       this.remove = remove;
       this.showAll = showAll;
    }
    function add(key,value) {
       this.dataStore[key] = value;
    }
    function find(key) {
       return this.dataStore[key];
    }
    function remove(key) {
       delete this.dataStore[key];
    }
    function showAll() {
       var keys =  Object.keys(this.dataStore),key;
       for(var i = 0; i < keys.length; ++i) {
          key = keys[i];
          console.log(key + " -> " + this.dataStore[key]);
       }
    }
    

    操作:demo

    添加其他功能:

    • 统计:
      function count() {
         return Object.keys(this.dataStore).length;
      }
    •  清空:
      function clear() {
         var keys =  Object.keys(this.dataStore),key;
         for(var i = 0; i < keys.length; ++i) {
            key = keys[i];
            delete this.dataStore[key];
         }
      }
    • 排序输出:对showAll进行优化
      function showSort(check,func) {
         var keys,key;
         if(check) {
            keys =  Object.keys(this.dataStore).sort(func);
         } else {
            keys =  Object.keys(this.dataStore);
         }
         for(var i = 0; i < keys.length; ++i) {
            key = keys[i];
            console.log(key + " -> " + this.dataStore[key]);
         }
      }  

    操作:demo;

  • 相关阅读:
    css-box-shadowing
    css- :before :after
    css: line-height 与box-sizing
    金蝶数据库后台追踪
    钉钉审批开发,空白内容
    asp.net c#语言实现钉钉鉴权验证
    钉钉事件回调c#测试完成
    钉钉C#发起审批实例demo
    asp.net c#语言实现钉钉鉴权验证
    图片码
  • 原文地址:https://www.cnblogs.com/jinkspeng/p/4030982.html
Copyright © 2020-2023  润新知