1

I'd like to find if there is a substring in any of the strings in my list of strings. I have a list like '("hi" "hey" "hello"). Using "some" I can find if the value "hi" is in this list. But how could I find if just "h" was in at least one of the strings in the list?

2
  • How do you use some to check if "hi" is in the list? Commented Nov 15, 2021 at 21:51
  • something like this, i guess (some #(clojure.string/includes? % "h") ["hi" "hello" "hey"]) Commented Nov 15, 2021 at 21:54

1 Answer 1

6

Clojure solutions:

(some #(clojure.string/includes? % "h") (list "hi" "hello" "hey"))
(some #(.contains % "h") (list "hi" "hello" "hey"))

ClojureScript solutions:

  • includes? from clojure.string (require clojure.string in ns form)
(ns my-app.core
  (:require [clojure.string :as string]))

(some #(string/includes? % "h") (list "hi" "hello" "hey"))
(some #(.includes % "h") (list "hi" "hello" "hey"))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.