"🔒"
(load-file "my.clj")
(require '[clojure.pprint :refer [pprint]])

(println "------ Articles ----------")
(pprint articles)
(println)

(println "------ Authors -----------")
(pprint authors)
#result
#------ Articles ----------
#[{:title "Intro to science", :authors [100 200], :likes 3}
# {:title "Programming machines", :authors [200 300], :likes 5}
# {:title "The digital age", :authors [300], :likes 6}
# {:title "Quantum computing", :authors [300 100], :likes 4}]
#
#------ Authors -----------
#[{:id 100, :name "Albert Einstein", :interest "Physics"}
# {:id 200, :name "Alan Turing", :interest "Computer Science"}
# {:id 300, :name "Jeff Dean", :interest "Programming"}]
#nil

"✍️"
; @workUnit
(defn article-count [] 
    (count articles)
    )
#result
##'user/article-count

"🔒"
; @check
; @title: total articles

(article-count)
#result
#4

"✍️"
; @workUnit
(defn total-likes []
    (reduce + [(:likes (articles 0)), (:likes (articles 1)), (:likes (articles 2)), (:likes (articles 3))])
    )
#result
##'user/total-likes

"🔒"
; @check
; @title: total likes

(total-likes)
#result
#18

"✍️"
; @workUnit
;(println (authors 0))
;(println (first authors))
(defn check-by-id [a i]
;    = (:id (authors 0)) i
    (= (:id a) i)
       )
(check-by-id (:id (authors 0)) 100)
#result
#false

"🔒"
; @check
; @title: check author id 100
(check-by-id (first authors) 100)
#result
#true

"🔒"
; @check
; @title: check author id 200
(check-by-id (first authors) 200)
#result
#false

"✍️"
; @workUnit
(defn authors-by-id [id]

;    (if (= (:id (authors 0)) 100) (authors 0) (println "Values are not equal"))
;    (for [i authors] (if (= (:id i) id) (i) ("")))
;    (for [i authors] (if (= (:id i) id) i ))
    (for [i authors :when (check-by-id i id)]
        i)
    )
#result
##'user/authors-by-id

"🔒"
; @check
; @title: author-by-id 100

(authors-by-id 100)
#result
#({:id 100, :name "Albert Einstein", :interest "Physics"})

"🔒"
; @check
; @title: author-by-id 200

(authors-by-id 200)
#result
#({:id 200, :name "Alan Turing", :interest "Computer Science"})

"🔒"
; @check
; @title: author-by-id 500

(authors-by-id 500)
#result
#()

"✍️"
; @workUnit

(defn resolve-ids [ids]
    (map id->name ids)
    )
#result
##'user/resolve-ids

"🔒"
; @check
; @title: resolve-ids check-1

(resolve-ids [100 200])
#result
#("Albert Einstein" "Alan Turing")

"🔒"
; @check
; @title: resolve-ids check-2

(resolve-ids [200 300 500])
#result
#("Alan Turing" "Jeff Dean" nil)

"✍️"
; @workUnit
(defn resolve-article [article] 
    (assoc article :authors (resolve-ids (:authors article )))
)
#result
##'user/resolve-article

"🔒"
; @check
; @title: resolve-article
(pprint (resolve-article (first articles)))
(pprint (resolve-article (second articles)))
#result
#{:title "Intro to science",
# :authors ("Albert Einstein" "Alan Turing"),
# :likes 3}
#{:title "Programming machines",
# :authors ("Alan Turing" "Jeff Dean"),
# :likes 5}
#nil

"✍️"
; @workUnit

(defn articles-with-names [] 
   (map resolve-article articles ) 
)
#result
##'user/articles-with-names

"🔒"
; @check
; @title: articles-with-names

(-> (articles-with-names) pprint)
#result
#({:title "Intro to science",
#  :authors ("Albert Einstein" "Alan Turing"),
#  :likes 3}
# {:title "Programming machines",
#  :authors ("Alan Turing" "Jeff Dean"),
#  :likes 5}
# {:title "The digital age", :authors ("Jeff Dean"), :likes 6}
# {:title "Quantum computing",
#  :authors ("Jeff Dean" "Albert Einstein"),
#  :likes 4})
#nil

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: