Logo

Programming-Idioms

History of Idiom 222 > diff from v18 to v19

Edit summary for version 19 by programming-idioms.org:
[Clojure] Variable name items

Version 18

2021-01-17, 17:51:39

Version 19

2021-01-17, 17:52:19

Idiom #222 Find first index of an element in list

Set i to the first index in list items at which the element x can be found, or -1 if items does not contain x.

Idiom #222 Find first index of an element in list

Set i to the first index in list items at which the element x can be found, or -1 if items does not contain x.

Extra Keywords
position
Extra Keywords
position
Code
(defn find-index [x c]
  (or (->> c
         (map-indexed vector)
         (filter #(= x (peek %)))
         ffirst) -1))
Code
(defn find-index [x items]
  (or (->> items
         (map-indexed vector)
         (filter #(= x (peek %)))
         ffirst) -1))