Complete the function/method so that it returns the url with anything after the anchor (#) removed.
Examples
"www.codewars.com#about" --> "www.codewars.com"
"www.codewars.com?page=1" -->"www.codewars.com?page=1"
不管使用任何語言,只要處理字串,regex 都是必須會的技能呢。
clojure.string/split
: splits string at # delimiter into vectorfirst
: takes the first element from the split result#"#"
: regex pattern that matches the anchor symbol; implement
(defn remove-url-anchor [url]
(first (clojure.string/split url #"#")))
; Example walkthrough:
; (remove-url-anchor "www.codewars.com#about")
; 1. split: "www.codewars.com#about" -> ["www.codewars.com" "about"]
; 2. first: ["www.codewars.com" "about"] -> "www.codewars.com"
; test
; execute implement function
(defn tester [arg exp]
(= (remove-url-anchor arg) exp))
; args & exception
(comment
(tester "www.codewars.com#about" "www.codewars.com")
(tester "www.codewars.com/katas/?page=1#about" "www.codewars.com/katas/?page=1")
(tester "www.codewars.com/katas/" "www.codewars.com/katas/"))