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

  • 相关阅读:
    合并字符串中的多个空格
    IfcSpecularRoughness
    IfcSpecularExponent
    IfcPresentableText
    IfcFontWeight
    IfcFontVariant
    uwb ifc模型定位測試
    IfcFontStyle
    IfcGeometricModelResource
    qt6安装
  • 原文地址:https://www.cnblogs.com/yudishow/p/4562829.html
Copyright © 2011-2022 走看看