js-检测字符串出现次数最多,并返回
function validateStr(val){ let obj = {}; let maxNum = -1; let maxStr; for(let i=0;i<val.length;i++){ if(!obj[val[i]]){ obj[val[i]] = 1; if( obj[val[i]]>maxNum){ maxNum = obj[val[i]]; maxStr = val[i]; } }else{ obj[val[i]]++; if( obj[val[i]]>maxNum){ maxNum = obj[val[i]]; maxStr = val[i]; } } } return{ maxNum, maxStr } }