Logo

Programming-Idioms

History of Idiom 222 > diff from v23 to v24

Edit summary for version 24 by Naxels:
[Ruby] Added note: .index() is not in Enumerable so use a supported data structure like Array

Version 23

2021-08-08, 13:32:02

Version 24

2021-08-08, 13:47:41

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.

Variables
i,x,items
Variables
i,x,items
Extra Keywords
position
Extra Keywords
position
Code
i = items.index(x) || -1
Code
i = items.index(x) || -1
Comments bubble
.index() is not in Enumerable so use a supported data structure like Array