关注
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 点赞 评论 收藏
分享
点赞 评论 收藏
分享
点赞 评论 收藏
分享
牛客热帖
更多
正在热议
更多
# 为了去实习,我赌上了___ #
20527次浏览 202人参与
# 硬件兄弟们 甩出你的华为奖状 #
116826次浏览 697人参与
# 百融云创求职进展汇总 #
209次浏览 0人参与
# uu们,春招你还来吗? #
12071次浏览 81人参与
# 面试紧张时你会有什么表现? #
15789次浏览 130人参与
# 哪一瞬间让你觉得“这班不如不上” #
11176次浏览 152人参与
# 2025年终总结 #
12643次浏览 213人参与
# 父母对你找工作是助力还是阻力? #
13263次浏览 193人参与
# 第一份工作能做外包吗? #
86071次浏览 577人参与
# 十二月请对我好一点 #
24895次浏览 332人参与
# 一人推荐一个值得做的项目 #
9096次浏览 118人参与
# 高薪高压 vs 低薪wlb,你怎么选? #
10868次浏览 114人参与
# 总结:哪家公司最喜欢泡池子 #
155524次浏览 559人参与
# 应届生初入职场,求建议 #
278781次浏览 2837人参与
# 降低公积金和取消房补怎么选 #
23425次浏览 79人参与
# 工作前VS工作后,你的心态变化 #
13146次浏览 155人参与
# 25届网易互娱暑实进度 #
91812次浏览 750人参与
# 晒一晒你收到的礼盒 #
87938次浏览 429人参与
# 你有哪些缓解焦虑的方法? #
41893次浏览 857人参与
# 工作中出现了XX情况正常吗 #
32132次浏览 211人参与
# 学历or实习经历,哪个更重要 #
202229次浏览 1072人参与