Skip to content

Instantly share code, notes, and snippets.

@tcrayford
Created May 22, 2010 01:29
Show Gist options
  • Save tcrayford/409661 to your computer and use it in GitHub Desktop.
Save tcrayford/409661 to your computer and use it in GitHub Desktop.
(defn my-count [coll]
(reduce (fn [n x] (inc n)) 0 coll))
(my-count [1 2 3 3]) ;; produces 4
(defn my-reverse [coll]
(reduce (fn [xs x] (into [x] xs)) [] coll))
(my-reverse [1 2 3]) ;; => [3 2 1]
(defn my-map [f coll]
(reduce (fn [xs x] (conj xs (f x))) [] coll))
(my-map inc [1 2 3]) ;; => [2 3 4]
(defn my-filter [pred coll]
(reduce (fn [xs x] (if (pred x)
(conj xs x)
xs))
[]
coll))
(my-filter even? [1 2 3]) ;; => [2]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment