I need to create a function. Within this I need the following to happen:
List 1: '(a 5 6)
List 2: '(c 8 10)
List 3: '(d 4 9)
Above are the lists. I need to ignore the 1st column of each list (this being a, c and d.) and then put the 2nd column in a vector. Then do the same for the 3rd column but a separate vector. Once this is done I'll carry out some small arithmetic between the two and write the results of each into a third vector.
I have very little Clojure experience and come from a Java background. I've tried to use let
By doing so I've only been able to create a var which stores the 2nd and 3rd item in a single list only. (eg List 1's 5 & 6.) However I need the vector to be [5 8 4]
.
(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])
))
assuming small-arithmetic
is a function taking the desired two vectors and returning the third vector.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.