Created
December 5, 2014 09:42
-
-
Save raspasov/f04635aaa7a6f2220108 to your computer and use it in GitHub Desktop.
Clojure substring search
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 string-contains? | |
"Searches a string s for any number of sub-strings, returns true on the first found, false otherwise" | |
[s sub & subs] | |
(if subs | |
(loop [subs (cons sub subs)] | |
(if-not (empty? subs) | |
(if-let [has-sub? (.contains s (first subs))] | |
has-sub? | |
(recur (rest subs))) | |
false)) | |
(.contains s sub))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment