Last active
May 22, 2019 18:17
-
-
Save renanpalmeira/cd5e6e90760259801e1b349a4a3b507c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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]}}))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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