在 clojure 字符串列表中查找子字符串

0 clojure clojurescript

我想查找我的字符串列表中的任何字符串中是否有子字符串。我有一个像'(“hi”“hey”“hello”)这样的列表。使用“some”我可以找到值“hi”是否在此列表中。但是我怎样才能找到列表中的至少一个字符串中是否只有“h”呢?

Mar*_*ůda 5

Clojure解决方案:

(some #(clojure.string/includes? % "h") (list "hi" "hello" "hey"))
Run Code Online (Sandbox Code Playgroud)
(some #(.contains % "h") (list "hi" "hello" "hey"))
Run Code Online (Sandbox Code Playgroud)

ClojureScript 解决方案:

  • includes?来自(表格中clojure.string要求)clojure.stringns
(ns my-app.core
  (:require [clojure.string :as string]))

(some #(string/includes? % "h") (list "hi" "hello" "hey"))
Run Code Online (Sandbox Code Playgroud)
(some #(.includes % "h") (list "hi" "hello" "hey"))
Run Code Online (Sandbox Code Playgroud)