Remember that indexes work from zero. So if you have a collection of 3 elements:
(nth ["a" "b" "c"] 2) => "c" (nth ["a" "b" "c"] 1) => "b" (nth ["a" "b" "c"] 0) => "a" I'd encourage you to open a REPL and try the solution you have to see what you get if you get stuck. Often some experimentation will show you what you're doing wrong. - James On 4 May 2014 15:58, Roelof Wobben <rwob...@hotmail.com> wrote: > oke, > > Then I think I have to work with a if then : > > The second test is already a vector but the thirth not > > (= (__ ["a" "b" "c"]) "b") > > (= (__ [[1 2] [3 4]]) [1 2]) > > I tried already the nth but I was also failing on the first. I think > because of count because you cannot know how many values you have. > > (fn secondlast [v] > (nth v (-(count v)1))) > > > Roelof > > Op zondag 4 mei 2014 16:49:45 UTC+2 schreef Lee: > >> >> >> On May 4, 2014, at 10:42 AM, Roelof Wobben <rwo...@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. > -- 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.