On 27 October 2010 12:54, Glen Rubin <rubing...@gmail.com> wrote:

> I have a sequence like this:
>
> [ [a b] [a b] [a b] [a b] ]
>
> where a and b are numbers.  I would like to return the vector and its
> index for which b is the least in this collection.
>
> For example, if my data is as follows
>
> [ [22 5] [56 8] [99 3] [43 76] ]
>
> I would like to return 3rd vector in the collection where b is lowest
> [99 3], but I also would like to know that it is the 3rd vector, so
> maybe something like:
>
> [99 3 3]
>
> any suggestions???
>
> thx a mil!!
>

Hi Glen,

Here's a solution:

user> (->> [[22 5] [56 8] [99 3] [43 76]]
           (map-indexed #(conj %2 (inc %1)))
           (sort-by second)
           (first))
[99 3 3]

Regards,
Stuart

-- 
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