function toWeirdCase(string){
return string.split(' ').map(function(word){
console.log(word)
return word.split('').map(function(letter, index){
return index % 2 == 0 ? letter.toUpperCase() : letter.toLowerCase()
}).join('');
}).join(' ');
}
console.log(toWeirdCase("this is big"));如:this is big 输出:ThIs Is BiG
一段语句 每个单词 基数位大写,偶数位小写
最新推荐文章于 2024-11-28 00:31:11 发布
本文介绍了一个JavaScript函数,该函数可以将输入的字符串转换为一种特殊格式,即每个单词中奇数位置的字母转换为大写,偶数位置的字母转换为小写。例如,将字符串thisisbig转换为ThIsIsBiG。
43

被折叠的 条评论
为什么被折叠?



