Javascript常用方法函数收集

字符串及数组类

判断一个字符串中出现次数最多的字符,统计这个次数

    var str = "zhaochucichuzuiduodezifu";
    var o = {};
    for (var i = 0, length = str.length; i < length; i++) {
    //        var char = str[i];
        var char = str.charAt(i);
        if (o[char]) {  //char就是对象o的一个属性,o[char]是属性值,o[char]控制出现的次数
            o[char]++;  //次数加1
        } else {
            o[char] = 1;    //若第一次出现,次数记为1
        }
    }
    console.log(o);   //输出的是完整的对象,记录着每一个字符及其出现的次数
    //遍历对象,找到出现次数最多的字符和次数
    var max = 0;
    var maxChar = null;
    for (var key in o) {
        if (max < o[key]) {
            max = o[key];   //max始终储存次数最大的那个
            maxChar = key;  //那么对应的字符就是当前的key
        }
    }
    console.log("最多的字符是" + maxChar);
    console.log("出现的次数是" + max);

Css Color Choosing

转载 A new approach to one of my biggest design weaknesses, using basic color theory, HSL, and Sass. In my work as a designer, color has never been my strong suit. I often try to avoid dealing with it entirely (as seen in the previous version of my site). Through education and experience, I’ve picked up the basics of color theory and mostly avoided catastrophe, but my rudimentary process