-
-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5c1882d
commit c783d3f
Showing
5 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,3 +18,5 @@ pom.xml.asc | |
*.lein-plugins/ | ||
*.lein-failures | ||
*.nrepl-port | ||
.clj-kondo | ||
.lsp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
In this exercise you will implement a partial set of utility routines to help a developer | ||
clean up identifier names. | ||
|
||
In the 4 tasks you will gradually build up the routine `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 `clean` function, an empty string should be returned. | ||
|
||
Note that the caller should avoid calling the routine `clean` with an empty identifier since such identifiers are ineffectual. | ||
|
||
### 1. Replace any spaces encountered with underscores | ||
|
||
Implement the `clean` function to replace any spaces with underscores. This also applies to leading and trailing spaces. | ||
|
||
```clojure | ||
(clean "my Id") | ||
;;=> "my___Id" | ||
``` | ||
|
||
### 2. Replace control characters with the upper case string "CTRL" | ||
|
||
Modify the `clean` function to replace control characters with the upper case string `"CTRL"`. | ||
|
||
```clojure | ||
(clean "my\0Id") | ||
;;=> "myCTRLId" | ||
``` | ||
|
||
### 3. Convert kebab-case to camelCase | ||
|
||
Modify the `clean` function to convert kebab-case to camelCase. | ||
|
||
```clojure | ||
(clean "à-ḃç") | ||
;;=> "àḂç" | ||
``` | ||
|
||
### 4. Omit Greek lower case letters | ||
|
||
Modify the `clean` function to omit any Greek letters in the range 'α' to 'ω'. | ||
|
||
```clojure | ||
(clean "MyΟβιεγτFinder") | ||
;;=> "MyΟFinder" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{:aliases {:test {:extra-paths ["test"] | ||
:extra-deps {com.cognitect/test-runner {:git/url "https://github.com/cognitect-labs/test-runner.git" | ||
:sha "209b64504cb3bd3b99ecfec7937b358a879f55c1"}} | ||
:main-opts ["-m" "cognitect.test-runner"]}}} |
35 changes: 35 additions & 0 deletions
35
exercises/concept/squeaky-clean/src/exercism/squeaky_clean.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
(ns exercism.squeaky-clean | ||
(:require [clojure.string :as str])) | ||
|
||
(defn escape-ctrl-char | ||
"If c is a control character, outputs \"CTRL\", otherwise itself" | ||
[c] | ||
(if (Character/isISOControl c) | ||
"CTRL" c)) | ||
|
||
(defn escape-ctrl [s] | ||
(apply str (map escape-ctrl-char s))) | ||
|
||
(defn camelize [s] | ||
(let [words (str/split s #"-")] | ||
(if (str/includes? s "-") | ||
(str/join "" (cons (first words) | ||
(cons (str/upper-case (ffirst (rest words))) | ||
(rest (first (rest words)))))) | ||
s))) | ||
|
||
(defn letters [s] | ||
(apply str (filter #(or (Character/isLetter %) | ||
(= \_ %)) | ||
s))) | ||
|
||
(defn clean-greek [s] | ||
(apply str (filter #(not (<= 945 (int %) 969)) s))) | ||
|
||
(defn clean [s] | ||
(-> s | ||
(str/replace " " "_") | ||
camelize | ||
escape-ctrl | ||
letters | ||
clean-greek)) |
30 changes: 30 additions & 0 deletions
30
exercises/concept/squeaky-clean/test/exercism/squeaky_clean_test.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
(ns exercism.squeaky-clean-test | ||
(:require [clojure.test :refer [deftest testing is]] | ||
exercism.squeaky-clean)) | ||
|
||
(deftest clean-single-letter | ||
(is (= "A" (exercism.squeaky-clean/clean "A")))) | ||
|
||
(deftest clean-clean-string | ||
(is (= "àḃç" (exercism.squeaky-clean/clean "àḃç")))) | ||
|
||
(deftest clean-string-with-spaces | ||
(is (= "my___Id" (exercism.squeaky-clean/clean "my Id")))) | ||
|
||
(deftest clean-string-with-control-char | ||
(is (= "myCTRLId" (exercism.squeaky-clean/clean "my\u0000Id")))) | ||
|
||
(deftest clean-string-with-no-letters | ||
(is (= "" (exercism.squeaky-clean/clean "😀😀😀")))) | ||
|
||
(deftest clean-empty-string | ||
(is (= "" (exercism.squeaky-clean/clean "")))) | ||
|
||
(deftest convert-kebab-to-camel-case | ||
(is (= "àḂç" (exercism.squeaky-clean/clean "à-ḃç")))) | ||
|
||
(deftest omit-lower-case-greek-letters | ||
(is (= "MyΟFinder" (exercism.squeaky-clean/clean "MyΟβιεγτFinder")))) | ||
|
||
(deftest combine-conversions | ||
(is (= "_AbcĐCTRL" (exercism.squeaky-clean/clean "9 -abcĐ😀ω\0")))) |