js 统计空格次数

vara=["a","","","","b","","","c",""];计算后的结果是{
a:3,
b:2,
c:1
}
临摹微笑
浏览 833回答 2
2回答

阿晨1998

((a,_)=>a.reduce((p,c)=>[_=c||_,_&&[p[_]=p[_]||0,!c&&(p[_]++)],p][2],{}))(["a","","","","b","","","c",""],undefined)会忽略第一个非空字符前的所有空字符。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript