Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
3
Task/Reverse-a-string/Clojure/reverse-a-string-1.clj
Normal file
3
Task/Reverse-a-string/Clojure/reverse-a-string-1.clj
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
(defn reverse-string [s]
|
||||
"Returns a string with all characters in reverse"
|
||||
(apply str (reduce conj '() s)))
|
||||
1
Task/Reverse-a-string/Clojure/reverse-a-string-2.clj
Normal file
1
Task/Reverse-a-string/Clojure/reverse-a-string-2.clj
Normal file
|
|
@ -0,0 +1 @@
|
|||
(defn str-reverse [s] (apply str (reverse s)))
|
||||
1
Task/Reverse-a-string/Clojure/reverse-a-string-3.clj
Normal file
1
Task/Reverse-a-string/Clojure/reverse-a-string-3.clj
Normal file
|
|
@ -0,0 +1 @@
|
|||
(apply str (interpose " " (reverse (.split "the quick brown fox" " "))))
|
||||
21
Task/Reverse-a-string/Clojure/reverse-a-string-4.clj
Normal file
21
Task/Reverse-a-string/Clojure/reverse-a-string-4.clj
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
(defn combining? [c]
|
||||
(let [type (Character/getType c)]
|
||||
;; currently hardcoded to the types taken from the sample string
|
||||
(or (= type 6) (= type 7))))
|
||||
|
||||
(defn group
|
||||
"Group normal characters with their combining characters"
|
||||
[chars]
|
||||
(cond (empty? chars) chars
|
||||
(empty? (next chars)) (list chars)
|
||||
:else
|
||||
(let [dres (group (next chars))]
|
||||
(cond (combining? (second chars)) (cons (cons (first chars)
|
||||
(first dres))
|
||||
(rest dres))
|
||||
:else (cons (list (first chars)) dres)))))
|
||||
|
||||
(defn str-reverse
|
||||
"Unicode-safe string reverse"
|
||||
[s]
|
||||
(apply str (apply concat (reverse (group s)))))
|
||||
Loading…
Add table
Add a link
Reference in a new issue