iT邦幫忙

2025 iThome 鐵人賽

DAY 17
0
Software Development

clojure 30 days系列 第 17

clojure 30 days - day 15

  • 分享至 

  • xImage
  •  

Problem Description

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.

Note

  • Character/isWhitespace - Java class method (static method)

Implementation

; implement
(defn vaporcode [string]
  (->> string
       (remove #(Character/isWhitespace %))
       (map #(clojure.string/upper-case (str %)))
       (clojure.string/join "  ")))

; test
(defn tester [arg exp]
  (= (vaporcode arg) exp))

; args & exception
(comment
  (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  ?"))


上一篇
clojure 30 days - day 14
系列文
clojure 30 days17
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言