-
-
Save tomjack/5b709e90dbb330d1fb62 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
(comment | |
user> (stabilize-by identity 3 [1 2 2 3 3 3 4 5 6 7]) | |
3 | |
user> (stabilize-by identity 3 [1 2 2 3 3 4 5 6 7]) | |
nil | |
user> (stabilize-by #(* % %) 3 [1 -1 2 -2 2 3 3 4 5 6 7]) | |
2) | |
(defn stabilize-by [f n s] | |
(when (seq s) | |
(let [fs (map f s) | |
[part rest] (split-with (comp #{(first fs)} f) s)] | |
(if (= n (count (take n part))) | |
(first part) | |
(recur f n rest))))) | |
(defn stabilize-by [f n s] | |
(->> s | |
(partition-by f) | |
(filter #(>= (count %) n)) | |
first first)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment