Yo are looking for indexOf (.indexOf vector value).

(.indexOf ["a" "b"] "b")
=> 1

(.indexOf ["a" "b" "b"] "b")
=> 1

Note how indexOf searches for the index of the first value which matches value.

To do what you ask, is a query over a vector, which requires a search on each 
element. This will take O(N) time. For a small list like in your example its 
probably good enough and not an issue.

If you want the name of the horse in a given position, that's a key lookup, 
which is ~O(1) time. You can use get:

(get ["a" "b"] 1)
=> "b"

If you really needed performance, you would need to combine a LinkedList and a 
map. Some datastructures do it for you under the hood, like Apache LinkedMap, 
amalloy ordered, java LinkedHashMap, etc.

Its possible to also just use sorted-map-by in a closure. But this only works 
if you're not going to add/update things to the datastructure after first 
creation.

See the example on clojuredocs: 
https://clojuredocs.org/clojure.core/sorted-map-by#example-542692d5c026201cdc327094

-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to