Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Sogrey opened this issue Apr 26, 2019 · 0 comments
Open

Comments

@Sogrey
Copy link
Owner

Sogrey commented Apr 26, 2019

var str = 'asdfssaaasasasasaa';

var json = {};

for (var i = 0; i < str.length; i++) {

    if(!json[str.charAt(i)]){
    
       json[str.charAt(i)] = 1;
    
    }else{
    
       json[str.charAt(i)]++;
    
    }

};var iMax = 0;var iIndex = '';for(var i in json){

    if(json[i]>iMax){
    
         iMax = json[i];
    
         iIndex = i;
    
    }

} 

console.log('出现次数最多的是:'+iIndex+'出现'+iMax+'次');
@Sogrey Sogrey added this to javascript in Web面经题 Sep 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Web面经题
javascript
Development

No branches or pull requests

1 participant