This function should test if the factor is a factor of base. Return true
if it is a factor or false
if it is not.
如果是 base 的因數回傳 true
; base 除以 factor
有餘數時回傳 false
。
;; (mod num div)
(ns kata.check-for-factor)
(defn check-for-factor [base factor]
(cond
(= (mod base factor) 0) true
:else false)
)
;; (rem num div)
;; rem can return remainder
;; = can be used to compare two parameters, cond function is not required for this case
(ns kata.check-for-factor)
(defn check-for-factor [base factor]
(= (rem base factor) 0)
)
;; (zero? num)
;; return true if num is 0
(ns kata.check-for-factor)
(defn check-for-factor [base factor]
(zero? (rem base factor))
)
;; if
(ns kata.check-for-factor)
(defn check-for-factor [base factor]
(if (= 0 (rem base factor)) true false))