Firstly, given that .indexOf is listed in the Clojure cheatsheet , I think it's idiomatic to use it.
Here are two more alternatives:
This seems like a second solution:
(let [[abc] (partition-by #(< % (apply max up5) up5)] [(concat ab) c]) ;=> [(1 2 3 4 5) (4 3 2 1)]
This next one looks more complicated, but it is more elegant in one respect: it delays the effect of < to include the = element, so there is no need to use conj or concat after that again insert the = element into the first sequence:
(let [the-max (apply max up5)] (loop [the-start [] the-rest up5 continue? true] (if continue? (let [this-one (first the-rest)] (recur (conj the-start this-one) (rest the-rest) (< this-one the-max))) [the-start the-rest]))) ;=> [[1 2 3 4 5] (4 3 2 1)]
Second element of the result: clojure.lang.PersistentVector$ChunkedSeq , btw. For most purposes, the sequence type should not matter, but you can apply vec to it if you really want a vector. Similarly for the results of my first example.
source share