On Apr 8, 1:13 pm, John Sanda <[email protected]> wrote: > [ > [1 2 3] > [2 5 1] > [4 2 6] > ] > > I am comparing the values in each of the columns, so the result should be [4 > 5 6] where the first element represents the largest value in the first > column, the second element represents the largest value in the second > column, etc.
The `map` function allows you to specify more than one collection. With multiple collections, the mapping function is passed an argument for each collection. So: (map + [1 2 3] [4 5 6]) => ((+ 1 4) (+ 2 5) (+ 3 6)) => (5, 7, 9) By combining this with `apply` and `max`, you can find the maximum value of each column: (defn max-columns [coll] (apply map max coll)) If we pass your vector to max-columns: (max-columns [[1 2 3] [2 5 1] [4 2 6]]) => (apply map max [[1 2 3] [2 5 1] [4 2 6]]) => (map max [1 2 3] [2 5 1] [4 2 6]) => ((max 1 2 4) (max 2 5 2) (max 3 1 6)) => (4 5 6) - James -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to [email protected] Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe, reply using "remove me" as the subject.
