Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (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]
Add Comment
Please, Sign In to add comment