Search code examples
clojure

How to access all of the second elements within a vector that is within a vector?


I have the following structure:

(def m [[120 2] [123 88] [234 77]])

And the value

(def z 10)

I am wanting to access all of the second elements within the smaller vectors (within m) and multiply them by z and then store the result with the first element of the vector.

I.e. do the calculation (* secondvectorelement z) And the result would look like [120 resultofcalculation]

So far I have tried:

(map #(* (second m) z ))

But I am stuck on this. TIA.


Solution

  • user=> (map (fn [v] [(first v) (* z (second v))]) m)
    ([120 20] [123 880] [234 770])