June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
16
Task/Range-extraction/Clojure/range-extraction.clj
Normal file
16
Task/Range-extraction/Clojure/range-extraction.clj
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
(use '[flatland.useful.seq :only (partition-between)])
|
||||
|
||||
(defn nonconsecutive? [[x y]]
|
||||
(not= (inc x) y))
|
||||
|
||||
(defn string-ranges [coll]
|
||||
(let [left (first coll)
|
||||
size (count coll)]
|
||||
(cond
|
||||
(> size 2) (str left "-" (last coll))
|
||||
(= size 2) (str left "," (last coll))
|
||||
:else (str left))))
|
||||
|
||||
(defn format-with-ranges [coll]
|
||||
(println (clojure.string/join ","
|
||||
(map string-ranges (partition-between nonconsecutive? coll)))))
|
||||
Loading…
Add table
Add a link
Reference in a new issue