On May 4, 2014, at 10:42 AM, Roelof Wobben <rwob...@hotmail.com> wrote:

> For 4clojure I have to find the second to last item.
> 
> So I did this:
> 
> (fn secondlast [v] 
>   (get v (-(count v)1)))
> 
> Now it's only failing at this test :  (= (__ (list 1 2 3 4 5)) 4)
> 
> Can anyone tell me where I did take the wrong way.


The "get" function with integer keys works for vectors but not for lists:

=> (get [7 8 9] 1)
8
=> (get '(7 8 9) 1)
nil

So one option would be to call "vec" on the list before calling get:

=> (get (vec '(7 8 9)) 1)
8

Another option would be to use "nth" instead of "get".

 -Lee

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