Clojure characters are java.lang.Character
primitives, and we can manipulate them via interop using the methods in the Character class:
(Character/isDigit \2)
;;=> true
Clojure ships with a powerful string processing library, clojure.string. This is often more idiomatic than interop.
In this exercise you will implement a partial set of utility routines to help a developer clean up identifier names.
In the 5 tasks you will gradually build up the function clean
.
A valid identifier comprises zero or more letters and underscores.
In all cases the input string is guaranteed to be non-nil. If an empty string is passed to the function, an empty string should be returned.
Note that the caller should avoid calling the function with an empty identifier since such identifiers are ineffectual.
Implement the clean
function to replace any spaces with underscores.
This also applies to leading and trailing spaces.
(clean "my Id")
;;=> "my___Id"
Modify the clean
function to replace control characters with
the upper case string "CTRL"
.
A character is considered to be an ISO control character if
its code is in the range '\u0000' through '\u001F'
or in the range '\u007F' through '\u009F'.
(clean "my\u007FId")
;;=> "myCTRLId"
Modify the clean
function to convert kebab-case to camelCase.
(clean "à -ḃç")
;;=> "à Ḃç"
Modify the clean
function to omit any characters that are not letters.
Note: The underscores must be preserved from the previous step.
(clean "1😀2😀3😀")
;; => ""
Modify the clean
function to omit any Greek letters in the range 'α' to 'ω'.
(clean "MyΟβιεγτFinder")
;;=> "MyΟFinder"
Sign up to Exercism to learn and master Clojure with 12 concepts, 85 exercises, and real human mentoring, all for free.