Guest User

Untitled

a guest
May 26th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. (defn my-count [coll]
  2. (reduce (fn [n x] (inc n)) 0 coll))
  3.  
  4. (my-count [1 2 3 3]) ;; produces 4
  5.  
  6. (defn my-reverse [coll]
  7. (reduce (fn [xs x] (into [x] xs)) [] coll))
  8.  
  9. (my-reverse [1 2 3]) ;; => [3 2 1]
  10.  
  11. (defn my-map [f coll]
  12. (reduce (fn [xs x] (conj xs (f x))) [] coll))
  13.  
  14. (my-map inc [1 2 3]) ;; => [2 3 4]
  15.  
  16. (defn my-filter [pred coll]
  17. (reduce (fn [xs x] (if (pred x)
  18. (conj xs x)
  19. xs))
  20. []
  21. coll))
  22.  
  23. (my-filter even? [1 2 3]) ;; => [2]
Add Comment
Please, Sign In to add comment