(defn
compare
"Comparator. Returns a negative number, zero, or a positive number\n when x is logically 'less than', 'equal to', or 'greater than'\n y. Uses IComparable if available and google.array.defaultCompare for objects\n of the same type and special-cases nil to be less than any other object."
[x y]
(cond
(identical? x y)
0
(nil? x)
-1
(nil? y)
1
(number? x)
(if
(number? y)
(garray/defaultCompare x y)
(throw (js/Error. (str "Cannot compare " x " to " y))))
(satisfies? IComparable x)
(-compare x y)
:else
(if
(and
(or (string? x) (array? x) (true? x) (false? x))
(identical? (type x) (type y)))
(garray/defaultCompare x y)
(throw (js/Error. (str "Cannot compare " x " to " y))))))