Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
19
Task/Call-a-function/Clojure/call-a-function-9.clj
Normal file
19
Task/Call-a-function/Clojure/call-a-function-9.clj
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
;; Here we have two functions to format a price depending on the country
|
||||
|
||||
(defn format-price-uk [price]
|
||||
(str "£" price))
|
||||
|
||||
(defn format-price-us [price]
|
||||
(str "$" price))
|
||||
|
||||
;; And one function that takes a price formatting function as an argument
|
||||
|
||||
(defn format-receipt [item-name price price-formatting-function]
|
||||
"Return the item name and price formatted according to the function"
|
||||
(str item-name
|
||||
" "
|
||||
(price-formatting-function price))) ;; Call the format function to get the right representation of the price
|
||||
|
||||
(format-receipt "Loo Roll" 5 format-price-uk); => "Loo Roll £5"
|
||||
|
||||
(format-receipt "Toilet Paper" 5 format-price-us); => "Toilet Paper $5"
|
||||
Loading…
Add table
Add a link
Reference in a new issue