Implement nth

This commit is contained in:
Kenneth Kostresevic 2021-12-17 14:05:39 +01:00
parent fac0657300
commit 35ff76d537

15
src/problems/21_nth.clj Normal file
View file

@ -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])