lambda-study-group / hacker-rank

Functional Path do hacker Rank

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Stucked on the Reverse a List problem

imteekay opened this issue · comments

commented

Hey people, I don't know if this is the best place to post it, but let's see :)

I am stucked on the Reverse a List problem.

I tried 2 different Clojure solutions:

1. defining a function

(defn rest-from-last
  [list]
  (take (- (count list) 1) list))

(defn reverse-a-list
  [list]
  (println (last list))
  (if (not-empty (rest-from-last list))
    (reverse-a-list (rest-from-last list))))

2. with a anonymous function

(defn rest-from-last
  [list]
  (take (- (count list) 1) list))

(fn [lst]
  (loop [list lst]
    (println (last list))
    (if (not-empty (rest-from-last list))
      (recur (rest-from-last list)))))

But I didn't get the right solution. Any advice for this problem?

commented

I actually don't know why, but I solved the problem without the rest-from-last function

Solution as PR here.

I will close this issue! :)