4
\$\begingroup\$

I had a look on Stack Overflow etc. on how to perform a contains ignore case with n given strings. Most answers suggested using regex for this task. Although it's a valid option, I prefer doing upper-case for both strings and apply a .contains afterwards.

The solution I came up with looks like this:

(defn desc-matches? [desc search-tokens] 
  (let [upper-desc (str/upper-case desc)
        upper-tokens (map str/upper-case search-tokens)]
    (some (partial #(.contains %1 %2) upper-desc) upper-tokens)))

Since I am relatively new to clojure, I'd appreciate if someone could have a look and tell me his/her thoughts on it.

UPDATE 1 - Applied Thumbnails suggestion

(defn desc-matches? [desc search-tokens] 
  (let [upper-desc (str/upper-case desc)
        upper-tokens (map str/upper-case search-tokens)]
    (some #(.contains upper-desc %) upper-tokens)))
\$\endgroup\$
  • 2
    \$\begingroup\$ looks good to me \$\endgroup\$ – toolkit Mar 18 '15 at 23:10
  • 1
    \$\begingroup\$ (partial #(.contains %1 %2) upper-desc) is just #(.contains upper-desc %). \$\endgroup\$ – Thumbnail Apr 9 '15 at 13:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.