Skip to content

Instantly share code, notes, and snippets.

@viebel
Last active May 26, 2019 03:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save viebel/0071a5ffd3019cbd70b8901b4d1cdecf to your computer and use it in GitHub Desktop.
Save viebel/0071a5ffd3019cbd70b8901b4d1cdecf to your computer and use it in GitHub Desktop.
(def github-db {"viebel"
{:username "viebel",
:name "Yehonathan Sharvit",
:email "ys@me.com",
:organizations ["ibm" "google"],
:repositories
{"klipse" {:name "klipse", :stars 23451, :forks 1254},
"titeuf" {:name "titeuf", :stars 1432, :forks 52},
"spirou" {:name "spirou", :stars 455, :forks 9}}},
"zepad"
{:username "zepad",
:name "Zachary Tanner",
:email "zt@me.com",
:organizations ["ibm"],
:repositories
{"tintin" {:name "tintin", :stars 522, :forks 43},
"donjon" {:name "donjon", :stars 987, :forks 76}}}
"kellyk"
{:username "kellyk",
:name "Kelly Kapowsky",
:email "kelly@kap.com",
:organizations [],
:repositories
{"spad" {:name "spad", :stars 122, :forks 12}}}})
;;;
(defn email-addresses [github-db]
(let [users-data (vals github-db)]
(map :email users-data)))
(email-addresses github-db)
;;;
(defn user->num-of-repos [user-data]
(let [username (:username user-data)
num-of-repos (:repositories user-data)]
(count num-of-repos)))
(defn num-of-repos [github-db]
(map user->num-of-repos (vals github-db)))
(num-of-repos github-db)
;;;
(defn user->repos-owned [user-data]
(let [username (:username user-data)
num-of-repos (count (:repositories user-data))]
(str username " owns " num-of-repos " repositories.")))
(defn owned-repos-sentence [github-db]
(mapv user->repos-owned (vals github-db)))
(owned-repos-sentence github-db)
;;;
(defn user->orgs [user-data]
(let [username (:username user-data)]
(case (count (:organizations user-data))
0 (str username " doesn't belong to any organization")
1 (str username " belongs to a single organization")
(str username " belongs to several organizations"))))
(defn org-sentence [github-db]
(mapv user->orgs (vals github-db)))
(org-sentence github-db)
;;; later
(defn repositories [github-db]
(let [users-data (vals github-db)
repos-map (map :repositories users-data)]
(mapcat vals repos-map)))
(repositories github-db)
;;;
(defn repositories-names [github-db]
(map :name (repositories github-db)))
(repositories-names github-db)
(defn organizations [github-db]
(distinct (mapcat :organizations (vals github-db))))
(organizations github-db)
(defn average-stars [github-db]
(let [stars (map :stars (repositories github-db))
sum-of-stars (apply + stars)
num-of-repos (count stars)]
(float (/ sum-of-stars num-of-repos))))
(average-stars github-db)
(defn organizations-starting-with-g [github-db]
(let [organizations (organizations github-db)]
(filter (fn [org] (clojure.string/starts-with? org "g")) organizations)))
(organizations-starting-with-g github-db)
(defn organizations-not-starting-with-g [github-db]
(let [organizations (organizations github-db)]
(remove (fn [org] (clojure.string/starts-with? org "g")) organizations)))
(organizations-not-starting-with-g github-db)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment