The task is to write a function that reverses a sequence. I am trying to do this as efficiently and clojure-ish as possible, but I can't figure out the best way. It doesn't feel right to create a variable and start appending items to that variable. What would seem idiomatic to me was if there was a way to do the following:
From the Clojure docs
(map-indexed (fn [idx itm] [idx itm]) "foobar")
--> ([0 \f] [1 \o] [2 \o] [3 \b] [4 \a] [5 \r])
What I have done is this:
(defn testing [x]
(map-indexed (fn [idx itm] [(- (count x) idx) itm]) x))
Which yields:
(testing "foobar")
--> ([6 \f] [5 \o] [4 \o] [3 \b] [2 \a] [1 \r])
What I can't figure out is how to essentially pack that back up into a new list with the correct indexes. Honestly, even the concept of declaring a variable is escaping me in Clojure at the moment. All my experience is with Python and Ruby.
reverseat clojuredocs.org/clojure_core/clojure.core/reverse#source.