Last active
August 29, 2015 14:05
-
-
Save krishnabhargav/cf4c5a382045a40d2cc8 to your computer and use it in GitHub Desktop.
functional way to determine if the elements in the sequence are all consecutive
This file contains hidden or 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
(defn are-consecutive? [input] | |
(let [sorted (sort input) | |
diff (map - (rest sorted) sorted) | |
all-one? (every? #(= 1 %) diff)] | |
all-one?)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment