Clojure has two functions: you can try: mod and rem . They work the same for positive numbers, but differently for negative numbers. Here is an example from the docs:
(mod -10 3) ; => 2 (rem -10 3) ; => -1
Update:
If you really want to convert your code to Clojure, you need to understand that Clojure's idiomatic solution will probably not be similar to your JavaScript solution. Here's a good solution, which I think does roughly what you want:
(defn change [amount] (zipmap [:quarters :dimes :nickels :pennies] (reduce (fn [acc x] (let [amt (peek acc)] (conj (pop acc) (quot amt x) (rem amt x)))) [amount] [25 10 5]))) (change 142) ; => {:pennies 2, :nickels 1, :dimes 1, :quarters 5}
You can find any of the features that you won't recognize on ClojureDocs . If you just donβt understand the style, then you probably need even more programming experience with higher order functions . I think 4Clojure is a good place to start.
source share