Skip to content

Instantly share code, notes, and snippets.

@renanpalmeira
Last active May 22, 2019 18:17
Show Gist options
  • Save renanpalmeira/cd5e6e90760259801e1b349a4a3b507c to your computer and use it in GitHub Desktop.
Save renanpalmeira/cd5e6e90760259801e1b349a4a3b507c to your computer and use it in GitHub Desktop.
(filter
identity
(map
(fn [[previous current]]
(let [previous-items (:items (last previous))
current-items (:items (last current))
previous-v (apply max previous-items)
current-great-previous (filter #(< % previous-v) current-items)]
(not (empty? current-great-previous))))
(partition 2 2 {} {"1" {:items [1 2 3]} "2" {:items [-1]} "3" {:items [2]}})))
(filter
(fn [[k v]] (:invalid v))
(reduce-kv
(fn [previous current-k current-v]
(let [{current-items :items} current-v
previous-items (:items (last (vals previous)))
current-great-previous (filter #(some (fn [v] (> v %)) previous-items) current-items)]
(if (not (empty? current-great-previous))
(assoc previous current-k (assoc current-v :invalid true))
(assoc previous current-k current-v))))
{}
{"1" {:items [1 2 3]} "2" {:items [-1]} "3" {:items [2]}}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment