function main(text){ //去掉标点符号 var arrText = text.split(''); for(var i=0; i<arrText.length; i++){ var index = arrText[i].charCodeAt(); if(index<65 && (index != 32) ){ arrText.splice(i,1); } } //始终用第一个单词进行比较,不断更改数组长度 text2 = arrText.join(''); var arr = text2.split(' '); var char = arr[0]; var count = 0; var len = arr.length; while(len>1){ console.log(char); for(var i=0; i<len; i++){ if(arr[i] == char){ count++; arr.splice(i,1); } } len = arr.length; console.log('-------------------'+count); char = arr[0]; count = 0; } } //var text = 'She is not afraid of changeWhile most people rather continue on living unfulfilled lives as long as their comfort zone remains intact, the empowered woman is all about embracing change. She understands growth cannot happen without change. She understands that change is the gift life offers you to choose your destiny. Therefore, she is not afraid of change because it is her stepping stone towards success. '; main(text);
点赞 评论

相关推荐

10-17 17:54
门头沟学院 Java
点赞 评论 收藏
分享
孙艹肘:校招不给三方直接让实习我都去了,,主打一个在学校呆着也是闲着,不如出来实习一下
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务