iT邦幫忙

2025 iThome 鐵人賽

DAY 16
0
Software Development

clojure 30 days系列 第 16

clojure 30 days - day 14

  • 分享至 

  • xImage
  •  

Problem Description

Trolls are attacking your comment section!

A common way to deal with this situation is to remove all of the vowels from the trolls' comments, neutralizing the threat.

Your task is to write a function that takes a string and return a new string with all vowels removed.

For example, the string "This website is for losers LOL!" would become "Ths wbst s fr lsrs LL!".

Note: for this kata y isn't considered a vowel.

Note

  • #"" -> In Clojure, #"" defines a regular expression literal.

Implementation

; implement
(defn disemvowel [string]
  (clojure.string/replace string #"(?i)[aeiou]" ""))

; (?i) -> This is a regex flag meaning case-insensitive. With it, a and A are treated as the same.

; [aeiou] -> Square brackets define a character class. [aeiou] means “match any one character that is a, e, i, o, or u”.

; test
; execute implement function
(defn tester [arg exp]
  (= (disemvowel arg) exp))

; args & exception
(comment
  (tester "This website is for losers LOL!" "Ths wbst s fr lsrs LL!"))

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

尚未有邦友留言

立即登入留言