Fork me on GitHub

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 ?

Drew Verlee12:09:33

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

Drew Verlee12:09:07

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> (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

thanks2 3

(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))

👍 9