CLJS error in sorting vectors

I’m moderately confident that you want to read this thread. It’s not clear what your particular use case is but if (sort-by (juxt first second #(nth % 2)) [...]) isn’t sufficient for your purposes [1] then that thread has some more general comparators that might be what you’re looking for. But it also contains an explanation of what’s going on under the hood (albeit in Clojure, not CLJS). Basically, sort by itself will rely on compare, which orders vectors like this:

  • vectors are sorted from fewest elements to most elements, with lexicographic ordering among equal length vectors.

Supplying < as a non-default comparator will break this behavior as it tries to interpret the vectors as numbers, which as Andy points out will give you a warning in the CLJS REPL. It may be worthwhile to note that in JVM Clojure it throws java.lang.ClassCastException because class clojure.lang.PersistentVector cannot be cast to class java.lang.Number. Simply put, less-than expects numbers.

[1]: It’s unclear from your clojuredocs/sort-by link what you wanted to do with juxt