How do I find the index of an item in a vector?

后端 未结 8 1911
孤独总比滥情好
孤独总比滥情好 2020-11-29 01:13

Any ideas what ???? should be? Is there a built in? What would be the best way to accomplish this task?

(def v [\"one\" \"two\" \"three\" \"two         


        
8条回答
  •  猫巷女王i
    2020-11-29 01:22

    I'd go with reduce-kv

    (defn find-index [pred vec]
      (reduce-kv
        (fn [_ k v]
          (if (pred v)
            (reduced k)))
        nil
        vec))
    

提交回复
热议问题