forked from iloveponies/structured-data
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstructured_data.clj
More file actions
130 lines (92 loc) · 2.64 KB
/
structured_data.clj
File metadata and controls
130 lines (92 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
(ns structured-data)
(defn do-a-thing [x]
(let [xpx (+ x x)]
(Math/pow xpx xpx)))
(defn spiff [v]
(+ (get v 0) (get v 2)))
(defn cutify [v]
(conj v "<3"))
(defn spiff-destructuring [v]
(let [first (get v 0)
third (get v 2)]
(+ first third)))
(defn point [x y]
[x y])
(defn rectangle [bottom-left top-right]
[bottom-left top-right])
(defn width [rectangle]
(let [ [[x1 y1] [x2 y2]] rectangle] (Math/abs (- x1 x2))))
(defn height [rectangle]
(let [ [[x1 y1] [x2 y2]] rectangle] (Math/abs (- y1 y2))))
(defn square? [rectangle]
(let [width (width rectangle)
height (height rectangle) ]
(= width height)))
(defn area [rectangle]
(let [width (width rectangle)
height (height rectangle)]
(* width height)))
(defn contains-point? [rectangle point]
(let [ [ [x1 y1] [x2 y2] ] rectangle
[x y] point ] (and (<= x1 x x2) (<= y1 y y2)) ))
(defn contains-rectangle? [outer inner]
(let [ [[x1 y1] [x2 y2]] outer
[[x3 y3] [x4 y4]] inner ]
(and (contains-point? outer (get inner 0)) (contains-point? outer (get inner 1)))))
(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]
(assoc book :authors (conj (:authors book) new-author)))
(defn alive? [author]
(not (contains? author :death-year)))
(defn element-lengths [collection]
(map count collection))
(defn second-elements [collection]
(let [get-second (fn [vec] (get vec 1))]
(map get-second collection)))
(defn titles [books]
(let [get-single-title (fn [book] (:title book))]
(map get-single-title books)))
(defn monotonic? [a-seq]
(or (apply >= a-seq) (apply <= a-seq)))
(defn stars [n]
(apply str (repeat n "*")))
(defn toggle [a-set elem]
(cond
(contains? a-set elem) (disj a-set elem)
:else (conj a-set elem)))
(defn contains-duplicates? [a-seq]
(cond
(> (count a-seq) (count (set a-seq))) true
:else false))
(defn old-book->new-book [book]
(assoc book :authors (set (:authors book))))
(defn has-author? [book author]
(contains? (:authors book) author))
(defn authors [books]
(apply clojure.set/union (map :authors books)))
(defn all-author-names [books]
:-)
(defn author->string [author]
:-)
(defn authors->string [authors]
:-)
(defn book->string [book]
:-)
(defn books->string [books]
:-)
(defn books-by-author [author books]
:-)
(defn author-by-name [name authors]
:-)
(defn living-authors [authors]
:-)
(defn has-a-living-author? [book]
:-)
(defn books-by-living-authors [books]
:-)
; %________%