Created
June 20, 2017 11:58
-
-
Save AndyObtiva/06ae34d241339f30056b069831973f4c to your computer and use it in GitHub Desktop.
Checks if a particular collection is a prefix of another collection (contained in it at the beginning). e.g. (prefix-of? [1 2] [1 2 3]) returns true whereas (prefix-of? [2 3] [1 2 3]) returns false.
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
(def prefix-of? | |
(fn [chunk full] | |
(or | |
(empty? chunk) | |
(and | |
(= | |
(take 1 chunk) | |
(take 1 full) | |
) | |
(prefix-of? | |
(drop 1 chunk) | |
(drop 1 full) | |
) | |
) | |
) | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment