Clojure List & # 8594; Vector

I need to create a function. Inside this, I need the following:

List 1: '(a 5 6)
List 2: '(c 8 10)
List 3: '(d 4 9)

Listed above. I need to ignore the 1st column of each list (these are a, c and d.), And then put the second column in the vector. Then do the same for the third column, but a separate vector. Once this is done, I will do a little arithmetic between them and write the results of each of them in the third vector.

I have very little Clojure experience and comes from the Java background. I tried to uselet

Thus, I was able to create a var that only saves the 2nd and 3rd elements in only one list. (for example, list 1 5 and 6.) However, I need a vector [5 8 4].

+4
source share
1
(defn answer [& [list-1 list-2 list-3 :as lists]]
   (->> lists                    ; ((a 5 6) (c 8 10) (d 4 9))
        (map rest)               ; ((5 6) (8 10) (4 9))
        (apply map vector)       ; ([5 8 4] [6 10 9])
        (apply small-arithmetic) ; (small-arithmetic [5 8 4] [6 10 9])
  ))

, small-arithmetic - , .

+4

Source: https://habr.com/ru/post/1613107/


All Articles