【今日湯底】
Write a function that converts any sentence into a V A P O R W A V E sentence. a V A P O R W A V E sentence converts all the letters into uppercase, and adds 2 spaces between each letter (or special character) to create this V A P O R W A V E effect.
Note that spaces should be ignored in this case.
(必須通過以下測試)
(ns kata.test
(:require [clojure.test :refer :all]
[kata :refer :all]))
(deftest basic-tests
(defn tester [s exp]
(testing (str "Testing for \"" s "\"")
(is (= (vaporcode s) exp))))
(tester "Lets go to the movies" "L E T S G O T O T H E M O V I E S")
(tester "Why isn't my code working?" "W H Y I S N ' T M Y C O D E W O R K I N G ?"))
【我的答案】
(ns kata)
(defn vaporcode [s]
(clojure.string/join " " (clojure.string/split (clojure.string/upper-case (.replaceAll s " " "")) #""))
)
思路:
【其他人的答案】
(ns kata
(:require [clojure.string :as str]))
(defn vaporcode
[s]
(->> s
(remove (partial = \space))
(str/join " ")
(str/upper-case)))
(ns kata (:require [clojure.string :refer [join replace upper-case]]))
(defn vaporcode [s] (join " " (vec (replace (upper-case s) " " ""))))