• js map


     1 // js通用方法
     2 
     3 // map对象定义
     4 function Map() {
     5     var struct = function(key, value) {
     6         this.key = key;
     7         this.value = value;
     8     };
     9 
    10     var put = function(key, value) {
    11         for (var i = 0; i < this.arr.length; i++) {
    12             if (this.arr[i].key === key) {
    13                 this.arr[i].value = value;
    14                 return;
    15             }
    16         }
    17         this.arr[this.arr.length] = new struct(key, value);
    18     };
    19 
    20     var get = function(key) {
    21         for (var i = 0; i < this.arr.length; i++) {
    22             if (this.arr[i].key === key) {
    23                 return this.arr[i].value;
    24             }
    25         }
    26         return null;
    27     };
    28 
    29     var remove = function(key) {
    30         var v;
    31         for (var i = 0; i < this.arr.length; i++) {
    32             v = this.arr.pop();
    33             if (v.key === key) {
    34                 continue;
    35             }
    36             this.arr.unshift(v);
    37         }
    38     };
    39 
    40     var size = function() {
    41         return this.arr.length;
    42     };
    43 
    44     var isEmpty = function() {
    45         return this.arr.length <= 0;
    46     };
    47     this.arr = new Array();
    48     this.get = get;
    49     this.put = put;
    50     this.remove = remove;
    51     this.size = size;
    52     this.isEmpty = isEmpty;
    53 }
  • 相关阅读:
    昨天又学到了dp
    LeetCode面试题17.13
    leetcode971
    今天又一题,单调队列leetcode862
    今天学到了一招,LeetCode863
    今天一道简单题,数组排序LeetCode973
    es面试题
    es的常用配置
    es基础一张图
    JMeter中引入外部的JAR包给bean shell 使用
  • 原文地址:https://www.cnblogs.com/XiaoGer/p/5139897.html
Copyright © 2020-2023  润新知