Look at the function below. I want to pass a vector of factors and test if any of the elements in the vector is a factor of x. How do I do that?
(defn multiple?
"Takes a seq of factors, and returns true if x is multiple of any factor."
([x & factors] (for [e m] ))
([x factor] (= 0 (rem x factor))))
You could try using
someandmap:Also
somereturnsnilif all tests fail, if you need it to actually returnfalse, you could put atrue?in there:Note that
someshort-circuits andmapis lazy, somultiple?stops as soon as a match is found. e.g. the following code tests against the sequence1,2,3,4,....Obviously this computation can only terminate if
multiple?doesn’t test against every number in the sequence.