codewar

来源:互联网 发布:唐斯2016赛季数据 编辑:程序博客网 时间:2024/06/08 05:11

codewar的js特点是需要熟悉js的新的语言特型,reduce map

leetcode考的算法



toWeirdCase("String" );//=> returns "StRiNg"toWeirdCase("Weird string case" );//=> returns "WeIrD StRiNg CaSe"





我的答案

return string.split(' ').map((a,i)=>(a.split('').map((b,j)=>(j%2==0?b.toUpperCase():b.toLowerCase())).join(''))).join(' ');


我看到最强的key


functiontoWeirdCase(string){return string.replace(/(\w{1,2})/g,(m)=>m[0].toUpperCase()+m.slice(1))}


原创粉丝点击