"🔒"
(def B 1e9)
#Result
##'user/B
"🔒"
(def social-network
{:members [ {:id 1000
:name "Jack"
:age 20
:hobbies ["sport", "reading"]}
{:id 1001
:name "Joe"
:occupation "electrician"}
{:id 1002
:name "Elon"
:occupation "CEO"
:hobbies ["space" "coding"]}]
:companies [{:name "GM"
:size 157000
:market-cap (* 55 B)}
{:name "Twitter"
:size 7000
:market-cap (* 41 B)}
{:name "Spotify"
:size 6000
:market-cap (* 15 B)}
]
:connections [{:person-id 1000
:company "Twitter"
:type :use
}
{:person-id 1001
:company "Twitter"
:type :owns}
{:person-id 1002
:company "GM"
:type :works}]
})
#Result
##'user/social-network
"🔒"
(require '[clojure.pprint :refer [pprint]])
(pprint social-network)
#Result
#{:members
# [{:id 1000, :name "Jack", :age 20, :hobbies ["sport" "reading"]}
# {:id 1001, :name "Joe", :occupation "electrician"}
# {:id 1002,
# :name "Elon",
# :occupation "CEO",
# :hobbies ["space" "coding"]}],
# :companies
# [{:name "GM", :size 157000, :market-cap 5.5E10}
# {:name "Twitter", :size 7000, :market-cap 4.1E10}
# {:name "Spotify", :size 6000, :market-cap 1.5E10}],
# :connections
# [{:person-id 1000, :company "Twitter", :type :use}
# {:person-id 1001, :company "Twitter", :type :owns}
# {:person-id 1002, :company "GM", :type :works}]}
#nil
"🔒"
; get the companies
(get social-network :companies)
#Result
#[{:name "GM", :size 157000, :market-cap 5.5E10} {:name "Twitter", :size 7000, :market-cap 4.1E10} {:name "Spotify", :size 6000, :market-cap 1.5E10}]
"🔒"
; get-in the market-cap of the first company
(get-in social-network [:companies 0 :market-cap])
#Result
#5.5E10
"🔒"
(def is-small (fn [company] (< (:size company) 10000)))
#Result
##'user/is-small
"🔒"
(filter is-small (:companies social-network))
#Result
#({:name "Twitter", :size 7000, :market-cap 4.1E10} {:name "Spotify", :size 6000, :market-cap 1.5E10})
To embed this program on your website, copy the following code and paste it into your website's HTML: