Project

General

Profile

Actions

Feature #6596

open

New method `Array#indexes`

Added by robin850 (Robin Dupret) almost 12 years ago. Updated over 3 years ago.

Status:
Assigned
Target version:
-
[ruby-core:45664]

Description

I submitted a pull request on Github that provides a new method Array#indexes. It departs from Array#index in such a way that it returns an array of indexes and not the single first occurrence that is relevant.

The reason I want this method is that I don't understand why Array#index returns a single index if the parameter is in the array several times.

Examples

a = [1, 2, 3, 1]
a.indexes(1) #=> [0, 3]
a.index(1) # => 0

In my opinion, it's not logical to return only a single index since 1 is in the array twice.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0