Logo

Programming-Idioms

History of Idiom 222 > diff from v25 to v26

Edit summary for version 26 by Naxels:
[Ruby] Add documentation URL for Array class

Version 25

2021-08-08, 13:51:40

Version 26

2021-08-08, 13:56:20

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
Comments bubble
.index() is not in Enumerable so use a supported data structure like Array
Doc URL
https://ruby-doc.org/core-3.0.2/Array.html#method-i-index