This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-09-06
Channels
- # announcements (3)
- # beginners (8)
- # calva (17)
- # cider (3)
- # clj-kondo (1)
- # cljs-dev (7)
- # clojure (11)
- # clojure-dev (9)
- # clojure-europe (1)
- # clojuredesign-podcast (4)
- # clojurescript (10)
- # conjure (13)
- # datomic (3)
- # emacs (3)
- # figwheel-main (1)
- # fulcro (12)
- # leiningen (8)
- # meander (20)
- # off-topic (85)
- # pathom (1)
- # shadow-cljs (39)
- # spacemacs (7)
- # tools-deps (44)
- # xtdb (5)
I have vector [33 "A" 2 "B" "C" "H"]
and I would like it to look [[33 "A"] [2 "B"] [1 "C"] [1 "H"]]
Any tips ?
Is the input missing a 1 on purpose? Assuming it isn't. (partition 2 [33 "A" 2 "B" "1" "C" "1" "H"]) would do the trick. Otherwise your input isn't uniform and I would use reduce or loop. Likely loop because you have to deal with 2 values at a time @gorniakowski
I guess if that's the only instance of that input you could use partition and then just update the last value.
Maybe something like this?
user> (def v [33 "A" 2 "B" "C" "H"])
#'user/v
user> (for [s (filter string? v)
:let [prev (get v (dec (.indexOf v s )))]]
[(if (int? prev) prev 1) s])
([33 "A"] [2 "B"] [1 "C"] [1 "H"])
Dear all, how can I calculate period in months given start and end dates in Clojure? Thanks
there are a few clojure library options, but the built in java time libraries work pretty well. check out https://docs.oracle.com/javase/8/docs/api/java/time/Period.html

(let [start-date (java.time.LocalDate/of 2018 2 1)
end-date (java.time.LocalDate/of 2020 5 10)]
(java.time.Period/between start-date end-date))