Js up to write your name in Pinyin, determine which letter appears

function fn(str) {
    var obj = {};
    for (var i = 0; i < str.length; i++) {
        if (!obj[str.charAt(i)]) {
            obj[str.charAt(i)] = 1;
        } else {
            obj[str.charAt(i)]++;
        }
    }
    var value = '';
    var count = 0;
    for (var i in obj) {
        if (obj[i] > count) {
            count =obj [I]; 
            value = I; 
        } 
    } 
    the console.log ( 'largest number of occurrences is' + value + ', the number of occurrences of' + COUNT); 
}

 

Guess you like

Origin www.cnblogs.com/gxx129/p/10981406.html