Skip to content

Commit 7887e25

Browse files
committed
update Candy-009
1 parent eb27b38 commit 7887e25

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

Candy-009/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
## 編號:CANDY-009
2+
3+
### 程式語言:JavaScript
4+
5+
#### 題目:移除網址中的錨點(Anchor)
6+
7+
```js
8+
function removeAnchor(url) {
9+
return url.split("#")[0];
10+
}
11+
12+
// 使用 split() 將 # 作為切割點, 第二個值為返回值
13+
// 由於已經被 # 分割成兩半, 一半為 # 之前, 另一半為 # 之後
14+
// 利用索引值抓取前面的值並回傳
15+
16+
console.log(removeAnchor("5xcampus.com")); // 印出 5xcampus.com
17+
console.log(removeAnchor("5xcampus.com/#about")); // 印出 5xcampus.com/
18+
console.log(removeAnchor("5xcampus.com/courses/?page=1#about")); // 印出 t5xcampus.com/courses/?page=1
19+
```

0 commit comments

Comments
 (0)