zoukankan      html  css  js  c++  java
  • js数组的去重与降维

    //  降维

    $(document).ready(function(){ var shapes = [ [ [[0, 4], [0, 5], [1, 4], [1, 5]] ], [ [[0, 3], [0, 4], [0, 5], [0, 6]], [[0, 4], [1, 4], [2, 4], [3, 4]] ], [ [[0, 4], [1, 4], [1, 5], [2, 5]], [[0, 4], [0, 5], [1, 3], [1, 4]] ], [ [[0, 5], [1, 4], [1, 5], [2, 4]], [[0, 3], [0, 4], [1, 4], [1, 5]] ], [ [[0, 4], [1, 3], [1, 4], [1, 5]], [[0, 4], [1, 4], [1, 5], [2, 4]], [[0, 3], [0, 4], [0, 5], [1, 4]], [[0, 5], [1, 4], [1, 5], [2, 5]] ], [ [[0, 3], [0, 4], [0, 5], [1, 3]], [[0, 4], [0, 5], [1, 5], [2, 5]], [[0, 5], [1, 3], [1, 4], [1, 5]], [[0, 4], [1, 4], [2, 4], [2, 5]] ], [ [[0, 3], [0, 4], [0, 5], [1, 5]], [[0, 5], [1, 5], [2, 4], [2, 5]], [[0, 3], [1, 3], [1, 4], [1, 5]], [[0, 4], [0, 5], [1, 4], [2, 4]] ] ]; var shapes = [ [ [[0, 4], [0, 5], [1, 4], [1, 5],[0, 4], [0, 5], [1, 4], [1, 5]] ], [ [[0, 3], [0, 4], [0, 5], [0, 6],[0, 3], [0, 4], [0, 5], [0, 6]], [[0, 4], [1, 4], [2, 4], [3, 4],[0, 4], [1, 4], [2, 4], [3, 4]] ], [ [[0, 4], [1, 4], [1, 5], [2, 5],[0, 4], [1, 4], [1, 5], [2, 5]], [[0, 4], [0, 5], [1, 3], [1, 4],[0, 4], [0, 5], [1, 3], [1, 4]] ], [ [[0, 5], [1, 4], [1, 5], [2, 4],[0, 5], [1, 4], [1, 5], [2, 4]], [[0, 3], [0, 4], [1, 4], [1, 5],[0, 3], [0, 4], [1, 4], [1, 5]] ], [ [[0, 4], [1, 3], [1, 4], [1, 5],[0, 4], [1, 3], [1, 4], [1, 5]], [[0, 4], [1, 4], [1, 5], [2, 4],[0, 4], [1, 4], [1, 5], [2, 4]], [[0, 3], [0, 4], [0, 5], [1, 4],[0, 3], [0, 4], [0, 5], [1, 4]], [[0, 5], [1, 4], [1, 5], [2, 5],[0, 5], [1, 4], [1, 5], [2, 5]] ], [ [[0, 3], [0, 4], [0, 5], [1, 3],[0, 3], [0, 4], [0, 5], [1, 3]], [[0, 4], [0, 5], [1, 5], [2, 5],[0, 4], [0, 5], [1, 5], [2, 5]], [[0, 5], [1, 3], [1, 4], [1, 5],[0, 5], [1, 3], [1, 4], [1, 5]], [[0, 4], [1, 4], [2, 4], [2, 5],[0, 4], [1, 4], [2, 4], [2, 5]] ], [ [[0, 3], [0, 4], [0, 5], [1, 5],[0, 3], [0, 4], [0, 5], [1, 5]], [[0, 5], [1, 5], [2, 4], [2, 5],[0, 5], [1, 5], [2, 4], [2, 5]], [[0, 3], [1, 3], [1, 4], [1, 5],[0, 3], [1, 3], [1, 4], [1, 5]], [[0, 4], [0, 5], [1, 4], [2, 4],[0, 4], [0, 5], [1, 4], [2, 4]] ] ]; Array.prototype.dr = function(){ var that = this; // 不能给this赋值 for (var i = 0; i < that.length; i++) { if(that[i] instanceof Array){ that = that.slice(0, i).concat(that[i], that.slice(i+1)); i--; } } return that; }; console.log(shapes.dr()); console.log((function(list) { var shape = list.shift(); return list.length === 0 ? shape : $.merge(shape, arguments.callee(list)); })($.extend(true, [], shapes))); });

    // 去重
    Array.prototype.unique = function(){
    var res = [], json = {}, i = 0, len = this.length;
    for(; i < len; i++) {
    if(!json[this[i]]) {
    res.push(this[i]);
    json[this[i]] = 1;
    }
    }

    return res;
    };

    源自:http://yanzhihong23.iteye.com/blog/2042805

  • 相关阅读:
    巴菲特最推崇的10本书
    如何锻炼剑术基本功
    Ubuntu 20.04 LTS, CUDA 11.2.0, NVIDIA 455 and libcudnn 8.0.4
    缘起性空
    Mac 每次都要执行source ~/.bash_profile 配置的环境变量才生效
    Calcite分析 -- Register
    go超时控制有4种写法,你知道吗?
    npm install node-sass报错处理
    IDEA + maven热部署及自动编译不生效问题
    1-STM32+CH395Q(以太网)远程升级篇(自建物联网平台)-STM32通过ch395使用http下载程序文件,升级程序(单片机程序轮训检查更新)
  • 原文地址:https://www.cnblogs.com/yudishow/p/4562829.html
Copyright © 2011-2022 走看看