Fork me on GitHub
#code-reviews
<
2021-05-24
>
jaihindhreddy14:05:21

While the following is less efficient, it is more readable (to me), because it manipulates sequences in smaller steps, as opposed to merging those steps into one loop:

(defn minimum-absolute-difference [xs]
  (->> (sort xs)
       (partition 2 1)
       (map (fn [[x y]] (Math/abs (- x y))))
       (apply min)))
Also, all classes in java.lang are imported and referred by ns. So, you can use Math/abs in addition to the full name java.lang.Math/abs

noisesmith17:05:22

it's not ns that does the scoping, but yes, most of java.lang is automatically in scope

thanks 3
jaihindhreddy17:05:56

I always thought it was ns. Perhaps i'm confusing the import of java.lang with the requiring and referring of things in clojure.core Edit: sorry for the misleading statement earlier.