Skip to content

Instantly share code, notes, and snippets.

@DadgadCafe
Created April 10, 2017 14:39
Show Gist options
  • Save DadgadCafe/18f27d0ecce55440a953e19f4c1e6a16 to your computer and use it in GitHub Desktop.
Save DadgadCafe/18f27d0ecce55440a953e19f4c1e6a16 to your computer and use it in GitHub Desktop.
notes of problem on 4clojure
;;;;;;;;;; Last Element
;; (= (__ [1 2 3 4 5]) 5)
;; (= (__ '(5 4 3)) 3)
;; (= (__ ["b" "c" "d"]) "d")
#(nth % (- (count %) 1))
#(nth % (dec (count %)))
;;;;;;;;;; Penultimate Element
;; (= (__ (list 1 2 3 4 5)) 4)
;; (= (__ ["a" "b" "c"]) "b")
;; (= (__ [[1 2] [3 4]]) [1 2])
#(nth % (- (count %) 2))
(comp second reverse)
;;;;;;;;;; Map Defaults
({:foo 1 :bar 2} :f 3) ; => 3
;; (= (__ 0 [:a :b :c]) {:a 0 :b 0 :c 0})
;; (= (__ "x" [1 2 3]) {1 "x" 2 "x" 3 "x"})
;; (= (__ [:a :b] [:foo :bar]) {:foo [:a :b] :bar [:a :b]})
#(apply hash-map (interleave %2 (repeat %1)))
;;;;;;;;;; todo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment