diff --git a/.gitignore b/.gitignore index ee508f76..4bcc085a 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,5 @@ pom.xml .lein-deps-sum .lein-failures .lein-plugins +.idea/ +*.iml diff --git a/.travis.yml b/.travis.yml index 455f3c0e..aaa8fab7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ language: clojure lein: lein2 script: lein2 midje :config .midje-grading-config.clj jdk: - - openjdk7 + - openjdk11 notifications: email: false webhooks: http://polar-hollows-8825.herokuapp.com/notifications diff --git a/project.clj b/project.clj index a7ba528d..3bc3776f 100644 --- a/project.clj +++ b/project.clj @@ -1,5 +1,6 @@ (defproject structured-data "1.0.0-SNAPSHOT" - :dependencies [[org.clojure/clojure "1.5.1"] + :dependencies [[org.clojure/clojure "1.10.0"] [iloveponies.tests/structured-data "0.1.0-SNAPSHOT"]] - :profiles {:dev {:plugins [[lein-midje "3.1.1"]]}}) + :profiles {:dev {:dependencies [[midje "1.9.5" :exclusions [org.clojure/clojure]]] + :plugins [[lein-midje "3.2.1"]]}}) diff --git a/src/structured_data.clj b/src/structured_data.clj index ebfe1ce4..6021501f 100644 --- a/src/structured_data.clj +++ b/src/structured_data.clj @@ -1,16 +1,20 @@ (ns structured-data) (defn do-a-thing [x] - :-) + (let [thing (+ x x)] + (Math/pow thing thing))) (defn spiff [v] - :-) + (let [first (get v 0) + second (get v 2)] + (+ first second))) (defn cutify [v] - :-) + (conj v "<3")) (defn spiff-destructuring [v] - :-) + (let [[a ? b] v] + (+ a b))) (defn point [x y] [x y]) @@ -19,96 +23,125 @@ [bottom-left top-right]) (defn width [rectangle] - :-) + (let [[[x1 ?] [x2 ?]] rectangle] + (- x2 x1))) (defn height [rectangle] - :-) + (let [[[? y1] [? y2]] rectangle] + (- y2 y1))) (defn square? [rectangle] - :-) + (== (height rectangle) (width rectangle))) (defn area [rectangle] - :-) + (* (height rectangle) (width rectangle))) (defn contains-point? [rectangle point] - :-) + (let [[[x1 y1] [x2 y2]] rectangle + [a b] point + left-in (>= a x1) + right-in (<= a x2) + bottom-in (>= b y1) + top-in (<= b y2)] + (and left-in right-in bottom-in top-in) + )) (defn contains-rectangle? [outer inner] - :-) + (let [[bottom-left top-right] inner + bottom-left-in (contains-point? outer bottom-left) + top-right-in (contains-point? outer top-right)] + (and bottom-left-in top-right-in) + )) (defn title-length [book] - :-) + (count (:title book))) (defn author-count [book] - :-) + (count (:authors book))) (defn multiple-authors? [book] - :-) + (> (author-count book) 1)) (defn add-author [book new-author] - :-) + (let [new-authors (conj (:authors book) new-author)] + (assoc book :authors new-authors))) (defn alive? [author] - :-) + (not (contains? author :death-year))) (defn element-lengths [collection] - :-) + (map count collection)) (defn second-elements [collection] - :-) + (let [second + (fn [coll] (get coll 1))] + (map second collection))) (defn titles [books] - :-) - -(defn monotonic? [a-seq] - :-) + (map :title books)) (defn stars [n] - :-) + (apply str (repeat n "*"))) + +(defn monotonic? [a-seq] + (or (apply <= a-seq) (apply >= a-seq))) (defn toggle [a-set elem] - :-) + (if (contains? a-set elem) + (disj a-set elem) + (conj a-set elem))) (defn contains-duplicates? [a-seq] - :-) + (< (count (set a-seq)) + (count a-seq))) (defn old-book->new-book [book] - :-) + (let [authors (set (:authors book))] + (assoc book :authors authors))) (defn has-author? [book author] - :-) + (contains? (:authors book) author)) (defn authors [books] - :-) + (set (apply concat (map :authors books)))) (defn all-author-names [books] - :-) + (set (map :name (authors books)))) (defn author->string [author] - :-) + (let [life-info + (fn [author] (if (or (:birth-year author) (:death-year author)) + (str " (" (:birth-year author) " - " (:death-year author) ")")))] + (apply str (:name author) (life-info author)))) (defn authors->string [authors] - :-) + (apply str (interpose ", " (map author->string authors)))) (defn book->string [book] - :-) + (apply str (interpose ", written by " [(:title book), (authors->string (authors [book]))]))) (defn books->string [books] - :-) + (cond + (empty? books) "No books." + (= (count books) 1) (str "1 book. " (book->string (get books 0)) ".") + :else (str (count books) " books. " (apply str (interpose ". " (map book->string books))) "."))) (defn books-by-author [author books] - :-) + (filter (fn [book] (has-author? book author)) books)) (defn author-by-name [name authors] - :-) + (let [results (filter (fn [author] (= name (:name author))) authors)] + (if (empty? results) + nil + (first results))) + ) (defn living-authors [authors] - :-) + (filter (fn [author] (alive? author)) authors)) (defn has-a-living-author? [book] - :-) + (< 0 (count (living-authors (:authors book))))) (defn books-by-living-authors [books] - :-) + (filter (fn [current] (has-a-living-author? current)) books)) -; %________%