Interesting. I never knew how to use areduce before. However, it
always scans the entire array. If you had a very long string (or other
collection), it might be better to scan backwards:

user> (defn last-indexof [cs c]
            (loop [n (dec (count cs))]
               (if (and (<= 0 n) (not= c (nth cs n)))
                   (recur (dec n))
                   n)))
#'user/last-indexof
user> (last-indexof "aabbccd" \c)
5
user> (last-indexof "aabbccd" \x)
-1

> areduce can be used too.
>
> (defn last-indexof [cs c]
>   (areduce cs i lst-idx -1
>     (if (= c (aget cs i)) i lst-idx)))
>
> (-> "aabbccd" to-array (last-indexof \c))
>
> Regards.
> Jestan Nirojan

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

Reply via email to