clojurescript iterate over collection of map

Viewed 60

I have a collection like this.

[{:id 101 :name "A"}, {:id 102 :name "B"}, {:id 103 :name "C"}]

I want to retrieve the complete map using id. For ex, i want to find for id = 102. so my function should return me this.

{:id 102 :name "B"}
2 Answers

i'm able to find a way to do so.here is my answer

cljs.user=> (def ab [{:id 101 :name "A"}, {:id 102 :name "B"}, {:id 103 :name "C"}])
#'cljs.user/ab

cljs.user=> (some #(when (= (:id %) 102) %) ab)
{:name "B", :id 102}

cljs.user=> 
(let [maps [{:id 1 :a "a"} {:id 2} {:id 3}]]
  (zipmap (map :id maps) maps))
Related