codewars-js练习
2021/2/10
github 地址
【1】<7kyu>【Hells Kitchen】
Obviously the words should be Caps, Every word should end with ‘!!!’, Any letter ‘a’ or ‘A’ should become ‘@’, Any other vowel should become ‘*’.
这些单词应该是大写的,每个单词都应该以“!!!”结尾’,任何字母’a’或’A’应该变成’@’,任何其他元音应该变成’*’。
example:
gordon('What feck damn cake'), 'WH@T!!!! F*CK!!!! D@MN!!!! C@K*!!!!'
gordon('are you stu pid'), '@R*!!!! Y**!!!! ST*!!!! P*D!!!!'
solution
<script type="text/javascript">
function gordon(a){
// 1先全部转为大写
var aU = a.toUpperCase();
var temp = aU.replace(/[aA]/g,'@').replace(/[AEIOU]/g,'*').split(' ');
for(var i=0;i<temp.length;i++){
temp[i] += '!!!!';
}
var result = temp.join(' ');
// console.log(result);
return result;
}
// // 验证
console.log(gordon('What feck damn cake'));// 'WH@T!!!! F*CK!!!! D@MN!!!! C@K*!!!!');
console.log(gordon('are you stu pid'));// '@R*!!!! Y**!!!! ST*!!!! P*D!!!!'
</script>
以上为自己思路供大家参考,可能有更优的思路。