---
tags: JavaScript, Codewars,7kyu V A P O R C O D E
title: Codewars - 7kyu V A P O R C O D E
---
###### tags: `Codewars` 、`7kyu V A P O R C O D E`、`JavaScript`
###### *date: 2022 / 11 / 3*
# 💪 7kyu V A P O R C O D E
**思考模式:** 將字串統一轉成大寫並每個字母間加一個空白,並回傳字串。
**解法一:**
1. 字母都轉大寫 `.toUpperCase()`
2. 把字母字串轉成陣列使用 `.filter()` 把空白處篩選。
3. 最後使用 `.join(" ")`組成字串再將字母間插入空白處。
```jsx=
function vaporcode(string) {
let char = [...string.toUpperCase()];
const strList = [...char].filter((str) => {
return str !== " ";
}).join(" ");
return strList;
};
console.log(vaporcode("Lets go to the movies")); //"L E T S G O T O T H E M O V I E S"
console.log(vaporcode("Why isnt my code working")); //"W H Y I S N T M Y C O D E W O R K I N G"
```
**解法二:**
1. 一樣使用 `.toUpperCase()` 每個字母都轉大寫。
2. 使用兩次 `.split().join()`,重組資料,最後再回傳。
```jsx=
function vaporcode(string) {
return string.toUpperCase().split(" ").join("").split("").join(" ");
};
console.log(vaporcode("Lets go to the movies")); //"L E T S G O T O T H E M O V I E S"
console.log(vaporcode("Why isnt my code working")); //"W H Y I S N T M Y C O D E W O R K I N G"
```