Skip to content

Commit

Permalink
Added exercises seq-max, longest-sequence, take-while and drop-while.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jani Rahkola committed Oct 21, 2012
1 parent 9a7e303 commit 26e5d63
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/recursion.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,24 @@
(defn my-last [coll]
:-)

(defn seq-max [a-seq]
:-)

(defn longest-sequence [a-seq]
[:-])

(defn my-filter [f a-seq]
[:-])

(defn sequence-contains? [elem a-seq]
:-)

(defn my-take-while [pred? a-seq]
[:-])

(defn my-drop-while [pred? a-seq]
[:-])

(defn seq= [a-seq b-seq]
:-)

Expand Down
22 changes: 22 additions & 0 deletions test/recursion_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@
(my-last [1 2 3]) => 3
(my-last [2 5]) => 5)

(facts "seq-max"
(seq-max [2 4 1 4]) => 4
(seq-max [2]) => 2
(seq-max []) => nil)

(facts "longest-sequence"
(longest-sequence [[1 2] [] [1 2 3]]) => [1 2 3]
(longest-sequence [[1 2]]) => [1 2]
(longest-sequence []) => nil)

(facts "my-filter"
(my-filter odd? [1 2 3 4]) => '(1 3)
(my-filter (fn [x] (> x 9000)) [12 49 90 9001]) => '(9001)
Expand All @@ -30,6 +40,18 @@
(sequence-contains? 3 [4 7 9]) => false
(sequence-contains? :pony []) => false)

(facts "my-take-while"
(my-take-while odd? [1 2 3 4]) => '(1)
(my-take-while odd? [1 3 4 5]) => '(1 3)
(my-take-while even? [1 3 4 5]) => '()
(my-take-while odd? []) => '())

(facts "my-drop-while"
(my-drop-while odd? [1 2 3 4]) => '(2 3 4)
(my-drop-while odd? [1 3 4 5]) => '(4 5)
(my-drop-while even? [1 3 4 5]) => '(1 3 4 5)
(my-drop-while odd? []) => '())

(facts "seq="
(seq= [1 2 4] '(1 2 4)) => true
(seq= [1 2 3] [1 2 3 4]) => false
Expand Down

0 comments on commit 26e5d63

Please sign in to comment.