Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 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