From 35ff76d537221d8f1fd722f21d6418bab51a2061 Mon Sep 17 00:00:00 2001 From: Kenneth Kostresevic Date: Fri, 17 Dec 2021 14:05:39 +0100 Subject: [PATCH] Implement nth --- src/problems/21_nth.clj | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/problems/21_nth.clj diff --git a/src/problems/21_nth.clj b/src/problems/21_nth.clj new file mode 100644 index 0000000..feaa676 --- /dev/null +++ b/src/problems/21_nth.clj @@ -0,0 +1,15 @@ +(ns problems.21-nth) + +(defn get-nth [n i] + (loop [[head & tail] n index i] + (if (= index 0) + head + (recur tail (dec index))))) + +(= (get-nth '(4 5 6 7) 2) 6) + +(= (get-nth [:a :b :c] 0) :a) + +(= (get-nth [1 2 3 4] 1) 2) + +(= (get-nth '([1 2] [3 4] [5 6]) 2) [5 6]) \ No newline at end of file