Array.filter_with_index
filter_with_indexpredicate
Group: Selections
Documentation
Selects all elements of this array which satisfy a predicate.
Arguments
predicate
: A function that takes an index and a list element and returns a boolean value that says whether that value should be included in the result.
Examples
Selecting all elements which are equal to their position in the array.
[0, 10, 2, 2].to_array.filter (==) == [0, 2].to_array