Skip to content

Instantly share code, notes, and snippets.

@cmiles74
Last active September 14, 2016 14:29
Show Gist options
  • Save cmiles74/bc84245ae08f926cb6e6f6c5c4cb55a9 to your computer and use it in GitHub Desktop.
Save cmiles74/bc84245ae08f926cb6e6f6c5c4cb55a9 to your computer and use it in GitHub Desktop.
More than one signature
(defn third
([lst]
(third (seq lst) 0))
([lst currentIndex]
(if (= (first lst) nil)
0
(if (= currentIndex 2)
(first lst)
(if (< currentIndex 2)
(third (rest lst) (+ currentIndex 1)))))))
(defn nth-third [lst]
(nth lst 2))
(defn loop-third [lst-in]
(let [lst (seq lst-in)]
(loop [item (first lst) remaining (rest lst) index 0]
(if (= index 2)
item
(recur (first remaining) (rest remaining) (inc index))))))
(defn filter-third [lst-in]
(let [lst (seq lst-in)]
(first (keep last
(filter #(= (first %) 2)
(map vector (range) lst))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment