Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You can make that somewhat more close to the correct computation, you don't need to sort the lists, you just need min values.

  (->> [2 3 4 7 5 3 11 12 7]
       (group-by even?)
       vals
       (map #(apply min %)))</pre>
However, operation like this can be made much more readable if you actually use variables like this:

  (defn min-even-odd [xs] 
    (let [evens (filter even? xs)
          odds (filter odd? xs)] 
       (list (apply min evens) (apply min odds))))

  (min-even-odd [2 3 4 7 5 3 11 12 7])
Which is a bit longer, but I think it makes more sense.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: