zoukankan      html  css  js  c++  java
  • 知识点笔记(二维数组排序、统计数组重复个数、)

    //统计数组内重复元素的个数
    let arr = ["leyi", "leyi", "leyi2", "leyi2", "leyi3", "leyi4", "leyi5"];
    let statInfo = [];
    arr=arr.sort();//这一步很重要 
    for (let i = 0; i < arr.length;) {
        let count = 0;
        for (let j = i; j < arr.length; j++) {
            if (arr[i] == arr[j]) {
                count++;
            }
        }
        statInfo.push({name: arr[i], count: count});
        i += count
    }
    console.info(statInfo);
    
    //二维数组排序(根据数组里第二个元素排序)
    const tdimensionArr = [["c", 3], ["b", 2], ["a", 1], ["e", 5], ["d", 4]];
    const sorTdimensionArr = tdimensionArr.sort(((a, b) = > (a[1] - b[1])));
    console.info(sorTdimensionArr);
    
    //求输出结果
    function Foo() {
        getName = function () {
            console.info(1);
        };
        return this;
    }
    Foo.getName = function () {
        console.info(2);
    };
    Foo.prototype.getName = function () {
        console.info(3);
    };
    var getName = function () {
        console.info(4);
    };
    function getName() {
        console.info(5);
    }
    
    Foo.getName(); //2
    getName(); //4
    Foo().getName(); //1
    getName();//1
    new Foo.getName();//2
    new Foo().getName();//3
    new new Foo().getName();//3
    
    
    
    源文章链接 http://www.cnblogs.com/xxcanghai/p/5189353.html  
  • 相关阅读:
    机器学习的定义和分类
    选股
    mysql修改密码
    快速排序
    php的错误类型
    MySQL数据库优化
    库存超卖问题
    循环处理
    kafka安装配置
    JavaScript、jQuery杂记
  • 原文地址:https://www.cnblogs.com/leyi/p/9308012.html
Copyright © 2011-2022 走看看