On 30 Jul 2010, at 15:03, Base wrote:

> Hi All
> 
> I have a vector in the following format:
> 
> [
>    ["M" "3.4" "5.6"] ["L" "4.2" "6.6"] ["L" "4.9" "7.9"] ["L" "1.1"
> "2.4"]["L" "5.4" "4.5"]
> ]
> 
> I would like to create a vector that contains the max values of each
> of the second and third values from this vector
> 
> in this case it would be:  [5.4, 7.9]
> 
> The method to do this that i have seen would be to
> 1.  Transpose the vector  using (apply map vector v)
> 2.  Discard the vector of Ms and Ls
> 3  Cast all of the remaining numbers to Float
> 4 Apply Max to each of the vectors.
> 
> There *has* to be a more elegant way to do this than I have been
> trying.


Here's my first take:

(def v [["M" "3.4" "5.6"] ["L" "4.2" "6.6"] ["L" "4.9" "7.9"] ["L" "1.1" 
"2.4"]["L" "5.4" "4.5"]])

(->> v
     (map rest)
     (apply map (fn [& vals]
                   (apply max (map #(Float/parseFloat %) vals)))))

=> (5.4 7.9)


-Steve

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to