Created
May 22, 2010 01:29
-
-
Save tcrayford/409661 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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